I need a Python script that uses the Tkinter module to create a static (not resizable) window.
I have a pretty simple Tkinter script but I don't want it to be resizable. How do I prevent a Tkinter window from being resizable? I honestly don't know what to do.
This is my script:
from tkinter import * import ctypes, os def callback(): active.set(False) quitButton.destroy() JustGo = Button(root, text=" Keep Going!", command= lambda: KeepGoing()) JustGo.pack() JustGo.place(x=150, y=110) #root.destroy() # Uncomment this to close the window def sleep(): if not active.get(): return root.after(1000, sleep) timeLeft.set(timeLeft.get()-1) timeOutLabel['text'] = "Time Left: " + str(timeLeft.get()) #Update the label if timeLeft.get() == 0: #sleep if timeLeft = 0 os.system("Powercfg -H OFF") os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") def KeepGoing(): active.set(True) sleep() quitButton1 = Button(root, text="do not sleep!", command=callback) quitButton1.pack() quitButton1.place(x=150, y=110) root = Tk() root.geometry("400x268") root.title("Alert") root.configure(background='light blue') timeLeft = IntVar() timeLeft.set(10) # Time in seconds until shutdown active = BooleanVar() active.set(True) # Something to show us that countdown is still going. label = Label(root, text="ALERT this device will go to sleep soon!", fg="red") label.config(font=("Courier", 12)) label.configure(background='light blue') label.pack() timeOutLabel = Label(root, text = 'Time left: ' + str(timeLeft.get()), background='light blue') # Label to show how much time we have left. timeOutLabel.pack() quitButton = Button(root, text="do not sleep!", command=callback) quitButton.pack() quitButton.place(x=150, y=110) root.after(0, sleep) root.mainloop()
Tkinter windows can be resized automatically by hovering and pulling over the window. We can disable the resizable property using the resizable(boolean value) method. We will pass false value to this method which will disable the window to be resized.
The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .
resizable() method in Tkinter | Python resizable() method is used to allow Tkinter root window to change it's size according to the users need as well we can prohibit resizing of the Tkinter window. So, basically, if user wants to create a fixed size window, this method can be used.
To set a specific size to the window when using Python tkinter, use geometry() function on the Tk() class variable. where width and height should be replaced with integers that represent the width and height of the window respectively.
The resizable
method on the root window takes two boolean parameters to describe whether the window is resizable in the X and Y direction. To make it completely fixed in size, set both parameters to False
:
root.resizable(False, False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With