如何制作 tkinter程序按钮在单击一次时仍保持按下并连续输入,直到它返回到原始状态时再次单击并且不再输出? (就像记录按钮的工作一样)
答案 0 :(得分:0)
您可以通过配置其relief
选项来控制按钮的外观。
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.recording = False
self.recButton = tk.Button(self, text='Record', command=self.clicked,
relief=tk.SUNKEN)
self.recButton.grid()
self.quitButton = tk.Button(self, text='Quit', command=self.quit)
self.quitButton.grid()
def clicked(self):
self.recording = not self.recording
if self.recording:
self.recButton.config(relief=tk.RAISED)
else:
self.recButton.config(relief=tk.SUNKEN)
app = Application()
app.master.title('Stateful Button')
app.mainloop()