I used this snippet to attempt full screen in Windows, and this is what it gave me:
How can I fix this? It seems like full screen isn't supported at all or something with Tkinter. It's Windows 8, if that matters. It's also Python v2.7.2.
Try win.state('zoomed'), where win is your Tk window instance.
Edit :
Try something like this. Simply treat this class like a Tk window class.
class Void (tk.Tk) :
def __init__ (self, color='black') :
tk.Tk.__init__(self)
self.wm_state('zoomed')
self.config(bg=color)
self.overrideredirect(True)
self.attributes('-topmost', True)
Related
i am trying to make a library management system in python using oops and tkinter.
here is the code:
from tkinter import *
class library():
def __init__(self):
self.screen=Tk()
self.title='LOGIN'
self.screen.minsize(800,600)
self.screen.maxsize(800,600)
self.screen.title(self.title)
c=Canvas(self.screen,bg='black').place(x=-10,y=0,height=1000,width=1000)
def screen_work(self):
self.screen_login().screen.destroy()
screen=Tk()
screen.title('LIBRARY MANAGEMENT')
#screen.attributes('-fullscreen',True)
def button(self):
Button(self.screen,text='press',bg='red').place(x=400,y=300)
lib=library()
mainloop()
now ,when i run this program a black screen of dimension '800x600; opens up without any errors but does not show any button.
As Bryan Oakley and JRiggles rightly stated, the button function is never called, so it wouldn't display
updated code
from tkinter import *
class library():
def __init__(self):
self.screen=Tk()
self.title='LOGIN'
self.screen.minsize(800,600)
self.screen.maxsize(800,600)
self.screen.title(self.title)
c=Canvas(self.screen,bg='black').place(x=-10,y=0,height=1000,width=1000)
def screen_work(self):
self.screen_login().screen.destroy()
screen=Tk()
screen.title('LIBRARY MANAGEMENT')
#screen.attributes('-fullscreen',True)
def button(self):
Button(self.screen,text='press',bg='red').place(x=400,y=300)
lib=library()
lib.button()
mainloop()
here's a great resource to learn tkinter in case you're interested!
https://realpython.com/python-gui-tkinter/
You don’t really need to use a function to add a button, you may just leave the button code near the end after the other functions. If you want to keep the function, I think you forgot to declare the function in order for the button to appear.
So, that's one of the strangest errors I've ever seen in Python. Hopefully, you can help me.
I have a tkinter mainwindow in main_file implementing images via:
from PIL import Image, ImageTk, ImageColor
#...
self.image_package_render = Image.open('ImagePackage.png')
self.image_package_render_data = np.array(self.image_package_render.convert('RGBA'))
self.plus_render = ImageTk.PhotoImage(self.image_package_render.resize((14, 14), box=(16, 20, 30, 34)))
When I launch the main_file directly, it works like a charm via root.mainloop().
Now I want to implement a splash screen by developing an external script:
import tkinter as tk
splash_root = tk.Tk()
splash_root.geometry("200x200")
splash_label = tk.Label(splash_root, text="Splash Screen", font=18)
splash_label.pack()
import main_file
splash_root.destroy()
tk.mainloop()
Now, however, main_file doesn't start up and throws me the error "_tkinter.TclError: image "pyimage12" doesn't exist".
(Also doesn't work, if I implement the splash_root directly in main_file).
It clearly has something to do with splash_root, but I can't get my head around it.
Cheers guys!
Update: Solved:
It appears that another mainloop apart from root.mainloop() in combination with another window besides a toplevel, just crashes the code somehow.
I implemented a toplevel window as splash like suggested here: Tkinter Show splash screen and hide main screen until __init__ has finished
Thank you!
I have been attempting to create a combobox that fits in with the rest of my UI; however the widget still looks like the default:
In my attempts, I have tried to "brute-force" the widget into adapting to the color with the following code but to no avail:
self.root = tk.Tk() # Parent Container
# Other UI elements declared
self.themeSel_combo_theme.configure(
"TCombobox",
background=self.theme.get('bg'),
foreground=self.theme.get('bg'),
fieldbackground=self.theme.get('bg'),
darkcolor=self.theme.get('bg'),
lightcolor=self.theme.get('bg'),
selectbackground=self.theme.get('bg'),
selectforeground=self.theme.get('bg'),
bordercolor=self.theme.get('bg'),
insertcolor=self.theme.get('bg'),
insertwidth=self.theme.get('bg'), # It uses a color, not a size value
arrowcolor=self.theme.get('bg')
)
self.themeSel_combo = ttk.Combobox(self.quickTheme_cont, style="TCombobox")
The code above was made using this website as a reference.
Note that self.theme.get('bg') returns #202020
Apologies for the inconvenience; I've decided to keep this thread in case someone else needs help with this. It turns out that using the following command for creating the parent container makes it so that ttk objects do not style properly:
self.root = tk.Tk()
Changing the aforementioned command to the following fixed the issue I was having:
self.root = tk.Toplevel()
Recently while using python tkinters declaration has not been working. What i mean by this is that a for any file where tkinter has not been imported before, simple code such as creating a window is not possible. Has anyone else encountered this issue? If so, how is it solved?
Any feedback is appreciated. Thanks.
The code is simply supposed to open a window in tkinter. But, when run, no window is displayed.
from tkinter import *
def sample():
window = Tk()
sample()
That's so interesting.
You have to use tkinter.Tk() instead of Tk().
Thanks
Try This :
from tkinter import * # Importing everything from the Tkinter module
win = Tk() # Initializing Tkinter and making a window
def sample():
new_win = Toplevel() # This creates a new window
sample()
win.mainloop() # If this is not there, the code won't work
I'm looking for very long time for a solution for this. I want to delete the Titlebar of a Tk window, like with the function "overridedirect()". My problem with that function is, that there is no icon on the taskbar of the OS.
I also tried it with "root.attributes("-fullscreen", 1)" and tried to scale it down, but that doesn't work either.
I hope somebody knows a good solution, thanks for help!
My code looks kind of like this now:
from tkinter import *
class Main(Frame):
def __init__(self, root):
**...**
#There are more classes after this one, but defined the same way
def main():
root = Tk()
root.geometry("800x400+0+0")
root.minsize(700, 400)
root.title("Title")
#root.overrideredirect(True)
#root.iconify()
##root.attributes('-topmost', 1)
##root.attributes("-fullscreen", 1)
##root.wm_state("zoomed")
if __name__ == "__main__":
main()
You cannot do what you want. You can either have no titlebar and no icon, or you can have a titlebar and icon. There is no way to get one without the other.