第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

tkinter gpio 狀態(tài)問題.. 我怎樣才能讓它更新標(biāo)簽以顯示最新狀態(tài)

tkinter gpio 狀態(tài)問題.. 我怎樣才能讓它更新標(biāo)簽以顯示最新狀態(tài)

這可以在啟動(dòng)時(shí)顯示標(biāo)簽,它顯示 gpio 9 的原始狀態(tài),但是當(dāng)您單擊按鈕時(shí),它不會(huì)更改標(biāo)簽文本。我希望它讀取 gpio 的實(shí)際狀態(tài),而不是單擊按鈕的事實(shí)。任何幫助,將不勝感激。#tktrial#!/usr/bin/env python3import RPi.GPIO as GPIOimport timetime.sleep(1)import tkinter as tkGPIO.setwarnings(False)GPIO.setmode(GPIO.BCM)#setup output pins for relay controlGPIO.setup(9, GPIO.OUT)   #power head 1 ch 4 relay#setup tkinterroot=tk.Tk()root.title("trial Aquarium")root.geometry("800x550")root.configure(bg="lightblue")photo1 = tk.PhotoImage(file="fish.gif") #defines a photo and gives the file namelabel1 = tk.Label(image=photo1)#puts label in the window in this case not text file must be in program folderlabel1.grid(row=10, column=0, columnspan=12) #says how to place the label#setup fontsftlab= 'Verdana', 13, 'bold'ftb= 'Verdana', 11, 'bold'#define functions for button     def pwrhd2on():    GPIO.output(9, GPIO.HIGH)def pwrhd2off():    GPIO.output(9, GPIO.LOW)state = GPIO.input(9)if state:    rt2=('On')else:    rt2=('Off')#setup exit buttonExitbutton= tk.Button(root, text="Exit", font=(ftb), width=6, bg="red", fg="white", command=root.destroy)Exitbutton.place(x=700, y=240)#setup powerhead 2 buttons and labellabelpwrhd2= tk.Label(root, text=("POWER HEAD  2"), font=(ftlab), bg="orange", fg="black")labelpwrhd2.place(x=0, y=496)butpwrhd2= tk.Button(root, text=("PUMP  ON"), font=(ftb), command=pwrhd2on)butpwrhd2.place(x=180, y=492)butpwrhd2= tk.Button(root, text=("PUMP OFF"), font=(ftb), command=pwrhd2off)butpwrhd2.place(x= 300, y= 492)labelpwrhd2gpio= tk.Label(root, text=("GPIO          9"), font=(ftlab), bg="black", fg="white")labelpwrhd2gpio.place(x= 670, y=496)labelpwrhd2state= tk.Label(root, text=rt2, font=(ftlab), bg="green", fg="black")labelpwrhd2state.place(x=570, y=496)root.mainloop()
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

在定義函數(shù)之前創(chuàng)建標(biāo)簽。利用


def pwrhd2on():

    GPIO.output(9, GPIO.HIGH)

    labelpwrhd2state.configure(text='GPIO 9 On')

def pwrhd2off():

    GPIO.output(9, GPIO.LOW)

    labelpwrhd2state.configure(text='GPIO 9 Off')

消除


state = GPIO.input(9)

if state:

    rt2=('On')

else:

    rt2=('Off')

text=rt2, 希望這會(huì)有所幫助!


查看完整回答
反對(duì) 回復(fù) 2022-11-09
  • 1 回答
  • 0 關(guān)注
  • 83 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)