[英]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.我需要一个使用 Tkinter 模块创建静态(不可调整大小)窗口的 Python 脚本。
I have a pretty simple Tkinter script but I don't want it to be resizable.我有一个非常简单的 Tkinter 脚本,但我不希望它可以调整大小。 How do I prevent a Tkinter window from being resizable?
如何防止 Tkinter 窗口调整大小? 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()
The resizable
method on the root window takes two boolean parameters to describe whether the window is resizable in the X and Y direction.根窗口上的
resizable
方法采用两个布尔参数来描述窗口是否在 X 和 Y 方向上可调整大小。 To make it completely fixed in size, set both parameters to False
:要使其大小完全固定,请将两个参数设置为
False
:
root.resizable(False, False)
You can also use: 您还可以使用:
root.resizable(0, 0)
Because 0 means False in Python 3. 因为在Python 3中0表示False。
I need a Python script that uses the Tkinter module to create a static (not resizable) window.我需要一个使用Tkinter模块创建静态(不可调整大小)窗口的Python脚本。
I have a pretty simple Tkinter script but I don't want it to be resizable.我有一个非常简单的Tkinter脚本,但我不希望它可调整大小。 How do I prevent a Tkinter window from being resizable?
如何防止Tkinter窗口可调整大小? 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.