【发布时间】:2023-03-11 10:51:01
【问题描述】:
我正在尝试使用 GUI 来打开和关闭 LED。
当我执行代码时,我得到一个空白框,标题为“tk”。
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
Label(frame, text='Turn LED ON').grid(row=0, column=0)
Label(frame, text='Turn LED OFF').grid(row=1, column=0)
self.button = Button(frame, text='LED 0 ON', command=self.convert0)
self.button.grid(row=2, columnspan=2)
def convert0(self, tog=[0]):
tog[0] = not tog[0]
if tog[0]:
self.button.config(text='LED 0 OFF')
else:
self.button.config(text='LED 0 ON')
root = tk.Tk()
app = Application(master=root)
app.mainloop()
【问题讨论】:
标签: python-3.x tkinter raspberry-pi3 gpio led