python - 如何使 Tkinter 窗口不可调整大小?

标签 python python-3.x tkinter static

我需要一个使用 Tkinter 模块创建静态(不可调整大小)窗口的 Python 脚本。

我有一个非常简单的 Tkinter 脚本,但我不希望它可调整大小。如何防止 Tkinter 窗口调整大小?老实说我不知道​​该怎么办。

这是我的脚本:

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()  

最佳答案

根窗口上的 ressized 方法采用两个 bool 参数来描述窗口是否可在 X 和 Y 方向上调整大小。要使其大小完全固定,请将两个参数设置为 False:

root.resizable(False, False)

关于python - 如何使 Tkinter 窗口不可调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37446710/

相关文章:

python - 使用上一列中的值填充 pandas 数据框中的 "None"值

python - Tkinter、Python 中框架的垂直滚动条

python - python 中数据的多维缩放

python - 通过总结 Python 中现有列表来创建新列表

python - 在第三个列表中指定的索引处创建一个列表,其中包含另一个列表中的项目

python - 获取调整后的 matplotlib 绘图窗口的大小

python - Tkinter Canvas 自动调整大小

python - 如何从包含Python字符串列表的列表创建2个字典

python-3.x - 如何使用 Amazon SQS 作为 Celery 代理,而不创建/列出队列?

python - Python 3 中的 For 循环