This question already has an answer here:
How can I resize root
window?
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
except ImportError:
import Tkinter as tk
root = tk.Tk()
tk.mainloop()
How can I resize window
?
try: # In order to be able to import tkinter for
import tkinter as tk # either in python 2 or in python 3
except ImportError:
import Tkinter as tk
root = tk.Tk()
window = tk.Toplevel(root)
tk.mainloop()
One could set the size of a window (be it a
Tk
instance orToplevel
instance) usinggeometry
method:or:
Additionally using geometry method one could also determine the upper-left corner of a window:
or perhaps both at once:
More generally one could use
winfo_toplevel
in order to easily set the size of the window from its children:Example
Here's an example that sets both the size and placement coordinates of a window through a children widget's reference: