python tkinter resize window on button click
from tkinter import *
root = Tk()
root.title("Title")
root.geometry("800x800")
# Resize on button click
def resize():
root.geometry("500x500")
button_1 = Button(root, text="Resize", command=resize)
button_1.pack(pady=20)
# Resize by parameters
def resize2():
w = 650
h = 650
root.geometry(f"{w}x{h}")
button_2 = Button(root, text="Resize", command=resize2)
button_2.pack(pady=20)
# Resize by user entered parameters
def resize3():
w = width_entry.get()
h = height_entry.get()
root.geometry(f"{w}x{h}")
width_label = Label(root, text="Width:")
width_label.pack(pady=20)
width_entry = Entry(root)
width_entry.pack()
height_label = Label(root, text="Height:")
height_label.pack(pady=20)
height_entry = Entry(root)
height_entry.pack()
button_3 = Button(root, text="Resize", command=resize3)
button_3.pack(pady=20)
root.mainloop()
Are there any code examples left?
New code examples in category Python