gpt4 book ai didi

python - 如何使 Python Tkinter 中的按钮保持按下状态直到按下另一个按钮

转载 作者:太空狗 更新时间:2023-10-30 00:40:46 24 4
gpt4 key购买 nike

我正在尝试找到一种方法让 Tkinter 使 Start 按钮保持按下状态,直到我按下 Stop 按钮。

from Tkinter import *
import tkMessageBox


class MainWindow(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("input")
self.master.minsize(250, 150)
self.grid(sticky=E+W+N+S)

top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)

for i in range(2):self.rowconfigure(i, weight=1)
self.columnconfigure(1, weight=1)

self.button0 = Button(self, text="Start", command=self.save, activeforeground="red")
self.button0.grid(row=0, column=0, columnspan=2, pady=2, padx=2, sticky=E+W+N+S)

self.button1 = Button(self, text="Stop", command=self.stop, activeforeground="red")
self.button1.grid(row=1, column=0, columnspan=2, pady=2, padx=2, sticky=E+W+N+S)

def save(self):
pass

def stop(self):
pass


if __name__=="__main__":
d=MainWindow()
d.mainloop()

最佳答案

所以你可以使用它的配置来设置按钮的浮雕,这让它看起来像是被按下了。

def save(self):
self.button0.config(relief=SUNKEN)
# if you also want to disable it do:
# self.button0.config(state=tk.DISABLED)
#...

def stop(self):
self.button0.config(relief=RAISED)
# if it was disabled above, then here do:
# self.button0.config(state=tk.ACTIVE)
#...

编辑

这显然不适用于 Mac OSx。此链接显示了应该的外观:http://www.tutorialspoint.com/python/tk_relief.htm

关于python - 如何使 Python Tkinter 中的按钮保持按下状态直到按下另一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23353746/

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