创建多个相互依赖的框架

时间:2017-03-21 00:47:44

标签: tkinter python-3.4

当我点击按钮时,我想让多个帧相互依赖。适合的代码是什么?我的代码如下。在我的GUI中我想从Raspberry Pi控制一个风扇速度,然后我点击一个按钮出现另一个窗口

import tkinter
import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT)
GPIO.output(14, GPIO.LOW)

q = GPIO.PWM(14,50)
num = 5

window = tkinter.Tk()

def fan_on():
    q.start(5)

def fan_off():
    q.ChangeDutyCycle(0)

def speed_up():
    global num
    num += 10
    q.ChangeDutyCycle(num)

def speed_down():
    global num
    num -= 10
    q.ChangeDutyCycle(num)

def quit():
    GPIO.cleanup()
    exit()


btn1 = tkinter.Button(window, text="Fan 0n" ,command=fan_on)
btn2 = tkinter.Button(window, text="Fan Off" ,command=fan_off)
btn3 = tkinter.Button(window, text="SPEED UP ⬆" ,command=speed_up)
btn4 = tkinter.Button(window, text="SPEED DOWN ⬇" ,command=speed_down)
#lbl = tkinter.Label(window, text="temp.°C")

btn5 = tkinter.Button(window, text="Quit" ,command=quit)

btn1.place(x=0 , y=20)
btn2.place(x=328, y=20)
btn3.pack()
btn4.pack()
btn5.place(y=300)
#lbl.place(x=180, y=180)

window.geometry("400x400")
window.mainloop()

0 个答案:

没有答案