python tkinter resize window on button click

Solutions on MaxInterview for python tkinter resize window on button click by the best coders in the world

showing results for - "python tkinter resize window on button click"
Luciano
27 Jan 2020
1from tkinter import *
2
3root = Tk()
4root.title("Title")
5root.geometry("800x800")
6
7# Resize on button click
8def resize():
9  root.geometry("500x500")
10
11button_1 = Button(root, text="Resize", command=resize)
12button_1.pack(pady=20)
13
14# Resize by parameters
15def resize2():
16  w = 650
17  h = 650
18  root.geometry(f"{w}x{h}")
19
20button_2 = Button(root, text="Resize", command=resize2)
21button_2.pack(pady=20)
22
23# Resize by user entered parameters
24def resize3():
25  w = width_entry.get()
26  h = height_entry.get()
27  root.geometry(f"{w}x{h}")
28
29width_label = Label(root, text="Width:")
30width_label.pack(pady=20)
31width_entry = Entry(root)
32width_entry.pack()
33
34height_label = Label(root, text="Height:")
35height_label.pack(pady=20)
36height_entry = Entry(root)
37height_entry.pack()
38
39button_3 = Button(root, text="Resize", command=resize3)
40button_3.pack(pady=20)
41
42root.mainloop()