gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:36:38 26 4
gpt4 key购买 nike

我需要一个使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com