Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Tkinter window not resizable?

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()   
like image 389
Squash Avatar asked May 25 '16 20:05

Squash


People also ask

How do I stop tkinter from resizing?

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.

How do I lock the size of a tkinter window?

The whole window size is frozen by using resizable(width=False, height=False) , or simply resizable(False, False) .

What does resizable do in tkinter?

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.

How do I change the default tkinter window size?

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.


1 Answers

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) 
like image 112
Bryan Oakley Avatar answered Oct 10 '22 00:10

Bryan Oakley