python界面切换_python – 初学者 – GUI切换按钮

我能请求一点帮助吗?我创建了一个带有切换按钮的GUI,用于切换LED,LED熄灭.

我现在要做的是添加一些代码来更改按钮的文本,因为它在两个状态之间切换.

我查了一些例子但是我不太清楚如何或者在哪里添加代码来使按钮文本切换.

谢谢你的帮助.

我的代码……

# Idle 07_02_LED ON using GUI

from time import sleep

from Tkinter import *

class App:

def __init__(self,master):

frame = Frame(master)

frame.pack()

Label(frame,text='Turn LED ON').grid(row=0,column=0)

Label(frame,text='Turn LED OFF').grid(row=1,column=0)

button = Button(frame,text='LED 0 ON',command=self.convert0)

button.grid(row=2,columnspan=2)

def convert0(self,tog=[0]):

tog[0] = not tog[0]

if tog[0]:

print('LED 0 OFF')

else:

print('LED 0 ON')

root = Tk()

root.wm_title('LED on & off program')

app = App(root)

root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值