Raspberry Pi系统在运行GUI时崩溃

时间:2014-07-08 04:31:41

标签: python user-interface tkinter raspberry-pi raspbian

我使用python tkinter编写了一个GUI,它在PC中正常运行(当我使用ssh控制Raspberry时)但在Raspberry pi中运行时总会导致系统崩溃。

当我尝试拖动GUI时,系统停止响应。即使我点击GUI的标题栏,系统也会崩溃。

该GUI包含以下功能:控制6个GPIO的PWM占空比,设置开启和关闭时间,通过pickle文件保存和读取设置。

问题是由raspripi引起的吗?或者是由我的低效程序引起的?或者它是由tkinter引起的?

欢迎任何评论,非常感谢!

代码是这样的:

import time

__author__='duanyujia'

#!/usr/bin/python
#-*- coding: iso-8859-1 -*-

#need to import some libraries to let this code work
from tkinter import *
from tkinter.filedialog import askopenfilename,asksaveasfilename
from tkinter.messagebox import showerror
from RPIO import PWM
import socket
import math
import pickle
import _thread

class LEDChooser(object):
def __init__(self):

    #initialize some vital variables
    self.start_button_state = 0
    self.r = 0
    self.hr = 0
    self.fr = 0
    self.b = 0
    self.w = 0
    self.t = 0
    self.f = 0
    self.start = 0
    self.stop = 0
    self.set = 0

    #initialize UI framework
    frame = Tk()
    self.frameThread = frame
    self.connection_status=StringVar()

    initialize PWM
    self.servo = PWM.Servo(0, 3000, 1)
    self.servo.set_servo(4, 2999)
    self.servo.set_servo(14,2999)
    self.servo.set_servo(15, 2999)
    self.servo.set_servo(17, 2999)
    self.servo.set_servo(18, 2999)
    self.servo.set_servo(7,2999)

    #title of the window
    frame.title("LED Contol Panel")


    ##main body of GUI
    Label(text="Current time:").grid(row=1,column=0)
    Label(text="Mode", relief=RIDGE, width=16).grid(row=7,column=0)
    Label(text="Red", relief=RIDGE, width=16).grid(row=7,column=1)
    Label(text="HyRed", relief=RIDGE, width=16).grid(row=7,column=2)
    Label(text="FrRed", relief=RIDGE, width=16).grid(row=7,column=3)
    Label(text="Blue", relief=RIDGE, width=16).grid(row=7,column=4)
    Label(text="White", relief=RIDGE, width=16).grid(row=7,column=5)
    Label(text="On", relief=RIDGE, width=20).grid(row=7,column=7,columnspan=5)
    Label(text="Off", relief=RIDGE, width=20).grid(row=7,column=13,columnspan=5)
    Label(text="Set Time", relief=RIDGE, width=20).grid(row=10,column=7,columnspan=5)

    #Timer
    Label(text=":",width=2).grid(row=8, column=8)
    Label(text=":",width=2).grid(row=8, column=10)
    Label(text=":",width=2).grid(row=8, column=14)
    Label(text=":",width=2).grid(row=8, column=16)
    Label(text=" ",width=2).grid(row=8, column=12)
    Label(text=" ",width=2).grid(row=8, column=6)

    self.start_time_h = StringVar()
    self.start_time_h.set("00")
    self.start_time_h_entry = Entry(frame, textvariable=self.start_time_h, width=4)
    self.start_time_h_entry.grid(row=8,column=7)

    self.start_time_m = StringVar()
    self.start_time_m.set("00")
    self.start_time_m_entry = Entry(frame, textvariable=self.start_time_m, width=4)
    self.start_time_m_entry.grid(row=8,column=9)

    self.start_time_s = StringVar()
    self.start_time_s.set("00")
    self.start_time_s_entry = Entry(frame, textvariable=self.start_time_s, width=4)
    self.start_time_s_entry.grid(row=8,column=11)

    self.stop_time_h = StringVar()
    self.stop_time_h.set("00")
    self.stop_time_h_entry = Entry(frame, textvariable=self.stop_time_h, width=4)
    self.stop_time_h_entry.grid(row=8,column=13)

    self.stop_time_m = StringVar()
    self.stop_time_m.set("00")
    self.stop_time_m_entry = Entry(frame, textvariable=self.stop_time_m, width=4)
    self.stop_time_m_entry.grid(row=8,column=15)

    self.stop_time_s = StringVar()
    self.stop_time_s.set("00")
    self.stop_time_s_entry = Entry(frame, textvariable=self.stop_time_s, width=4)
    self.stop_time_s_entry.grid(row=8,column=17)

    self.save_start_time_h = StringVar()
    self.save_start_time_h.set("")
    Label(textvariable=self.save_start_time_h).grid(row=11, column=7)
    self.save_start_time_m = StringVar()
    self.save_start_time_m.set("")
    Label(textvariable=self.save_start_time_m).grid(row=11, column=9)
    self.save_start_time_s = StringVar()
    self.save_start_time_s.set("")
    Label(textvariable=self.save_start_time_s).grid(row=11, column=11)
    self.save_stop_time_h = StringVar()
    self.save_stop_time_h.set("")
    Label(textvariable=self.save_stop_time_h).grid(row=11, column=13)
    self.save_stop_time_m = StringVar()
    self.save_stop_time_m.set("")
    Label(textvariable=self.save_stop_time_m).grid(row=11, column=15)
    self.save_stop_time_s = StringVar()
    self.save_stop_time_s.set("")
    Label(textvariable=self.save_stop_time_s).grid(row=11, column=17)

    #current time
    self.timeText = Label(frame, text="")
    self.timeText.grid(row=1, column=1)

    #self.connection_status=StringVar()
    self.update_timeText()

    #default modes
    self.light_mode = StringVar()
    self.light_mode.set(1)

    #start button and exit and save and read button
    self.start_button = Button(frame, text='startnow')
    self.start_button.grid(row=14, column=0)
    self.start_button.bind('<ButtonRelease-1>', self.start_now)

    self.save_button = Button(frame, text='save',relief = 'raised')
    self.save_button.grid(row=14, column=1)
    self.save_button.bind('<ButtonRelease-1>', self.save_setting)

    self.read_button = Button(frame, text='read')
    self.read_button.grid(row=14, column=2)
    self.read_button.bind('<ButtonRelease-1>', self.read_setting)

    exit_button = Button(frame, text='exit')
    exit_button.grid(row=14, column=3)
    exit_button.bind('<ButtonRelease-1>', exit)

    exit_button = Button(frame, text='set time')
    exit_button.grid(row=14, column=4)
    exit_button.bind('<ButtonRelease-1>', self.set_time)

    #Germination mode setting
    self.light_mode_switch1 = Radiobutton(frame, variable=self.light_mode,
                                          value=1, command=self.customEnable, text='Germination')                                                                                    
    self.light_mode_switch1.grid(row=8, column=0)

    self.value_r_g = StringVar()
    self.value_r_g.set("0")
    self.value_r_g_entry = Entry(frame, textvariable=self.value_r_g)
    self.value_r_g_entry.grid(row=8,column=1)

    self.value_hr_g = StringVar()
    self.value_hr_g.set("0")
    self.value_hr_g_entry = Entry(frame, textvariable=self.value_hr_g)
    self.value_hr_g_entry.grid(row=8,column=2)

    self.value_fr_g = StringVar()
    self.value_fr_g.set("0")
    self.value_fr_g_entry = Entry(frame, textvariable=self.value_fr_g)
    self.value_fr_g_entry.grid(row=8,column=3)

    self.value_b_g = StringVar()
    self.value_b_g.set("0")
    self.value_b_g_entry = Entry(frame, textvariable=self.value_b_g)
    self.value_b_g_entry.grid(row=8,column=4)

    self.value_w_g = StringVar()
    self.value_w_g.set("0")
    self.value_w_g_entry = Entry(frame, textvariable=self.value_w_g)
    self.value_w_g_entry.grid(row=8,column=5)

    #Seedling mode setting
    self.light_mode_switch2 = Radiobutton(frame, variable=self.light_mode,
                                          value=2, command=self.customEnable, text='Seedling')
    self.light_mode_switch2.grid(row=9, column=0)

    self.value_r_s = StringVar()
    self.value_r_s.set("0")
    self.value_r_s_entry = Entry(frame, textvariable=self.value_r_s)
    self.value_r_s_entry.grid(row=9,column=1)

    self.value_hr_s = StringVar()
    self.value_hr_s.set("0")
    self.value_hr_s_entry = Entry(frame, textvariable=self.value_hr_s)
    self.value_hr_s_entry.grid(row=9,column=2)

    self.value_fr_s = StringVar()
    self.value_fr_s.set("0")
    self.value_fr_s_entry = Entry(frame, textvariable=self.value_fr_s)
    self.value_fr_s_entry.grid(row=9,column=3)

    self.value_b_s = StringVar()
    self.value_b_s.set("0")
    self.value_b_s_entry = Entry(frame, textvariable=self.value_b_s)
    self.value_b_s_entry.grid(row=9,column=4)

    self.value_w_s = StringVar()
    self.value_w_s.set("0")
    self.value_w_s_entry = Entry(frame, textvariable=self.value_w_s)
    self.value_w_s_entry.grid(row=9,column=5)

    #Vegetative mode setting
    self.light_mode_switch3 = Radiobutton(frame, variable=self.light_mode,
                                          value=3, command=self.customEnable, text='Vegetative')
    self.light_mode_switch3.grid(row=10, column=0)

    self.value_r_v = StringVar()
    self.value_r_v.set("0")
    self.value_r_v_entry = Entry(frame, textvariable=self.value_r_v)
    self.value_r_v_entry.grid(row=10,column=1)

    self.value_hr_v = StringVar()
    self.value_hr_v.set("0")
    self.value_hr_v_entry = Entry(frame, textvariable=self.value_hr_v)
    self.value_hr_v_entry.grid(row=10,column=2)

    self.value_fr_v = StringVar()
    self.value_fr_v.set("0")
    self.value_fr_v_entry = Entry(frame, textvariable=self.value_fr_v)
    self.value_fr_v_entry.grid(row=10,column=3)

    self.value_b_v = StringVar()
    self.value_b_v.set("0")
    self.value_b_v_entry = Entry(frame, textvariable=self.value_b_v)
    self.value_b_v_entry.grid(row=10,column=4)

    self.value_w_v = StringVar()
    self.value_w_v.set("0")
    self.value_w_v_entry = Entry(frame, textvariable=self.value_w_v)
    self.value_w_v_entry.grid(row=10,column=5)

    #Flowering mode setting
    self.light_mode_switch4 = Radiobutton(frame, variable=self.light_mode,
                                          value=4, command=self.customEnable, text='Flowering')
    self.light_mode_switch4.grid(row=11, column=0)

    self.value_r_f = StringVar()
    self.value_r_f.set("0")
    self.value_r_f_entry = Entry(frame, textvariable=self.value_r_f)
    self.value_r_f_entry.grid(row=11,column=1)

    self.value_hr_f = StringVar()
    self.value_hr_f.set("0")
    self.value_hr_f_entry = Entry(frame, textvariable=self.value_hr_f)
    self.value_hr_f_entry.grid(row=11,column=2)

    self.value_fr_f = StringVar()
    self.value_fr_f.set("0")
    self.value_fr_f_entry = Entry(frame, textvariable=self.value_fr_f)
    self.value_fr_f_entry.grid(row=11,column=3)

    self.value_b_f = StringVar()
    self.value_b_f.set("0")
    self.value_b_f_entry = Entry(frame, textvariable=self.value_b_f)
    self.value_b_f_entry.grid(row=11,column=4)

    self.value_w_f = StringVar()
    self.value_w_f.set("0")
    self.value_w_f_entry = Entry(frame, textvariable=self.value_w_f)
    self.value_w_f_entry.grid(row=11,column=5)

    #Custom mode setting
    self.light_mode_switch5 = Radiobutton(frame, variable=self.light_mode,
                                          value=5, command=self.customEnable, text='Custom')
    self.light_mode_switch5.grid(row=12, column=0)

    self.value_r_c = StringVar()
    self.value_r_c.set("0")
    self.value_r_c_entry = Entry(frame, textvariable=self.value_r_c)
    self.value_r_c_entry.grid(row=12,column=1)

    self.value_hr_c = StringVar()
    self.value_hr_c.set("0")
    self.value_hr_c_entry = Entry(frame, textvariable=self.value_hr_c)
    self.value_hr_c_entry.grid(row=12,column=2)

    self.value_fr_c = StringVar()
    self.value_fr_c.set("0")
    self.value_fr_c_entry = Entry(frame, textvariable=self.value_fr_c)
    self.value_fr_c_entry.grid(row=12,column=3)

    self.value_b_c = StringVar()
    self.value_b_c.set("0")
    self.value_b_c_entry = Entry(frame, textvariable=self.value_b_c)
    self.value_b_c_entry.grid(row=12,column=4)

    self.value_w_c = StringVar()
    self.value_w_c.set("0")
    self.value_w_c_entry = Entry(frame, textvariable=self.value_w_c)
    self.value_w_c_entry.grid(row=12,column=5)

    #setting default size of the windows
    frame.geometry("1400x500+300+300")

    #start the UI
    frame.mainloop()

    #enable disable
def customEnable(self):
    if self.light_mode.get()=='1':
        self.light_mode_switch1.configure(state="normal")
        self.light_mode_switch1.update()
        self.r = int(self.value_r_g.get())
        self.value_r_g_entry.configure(state="normal")
        self.value_r_g_entry.update()
        self.value_hr_g_entry.configure(state="normal")
        self.value_hr_g_entry.update()
        self.value_fr_g_entry.configure(state="normal")
        self.value_fr_g_entry.update()
        self.value_b_g_entry.configure(state="normal")
        self.value_b_g_entry.update()
        self.value_w_g_entry.configure(state="normal")
        self.value_w_g_entry.update()

        self.light_mode_switch2.configure(state="normal")
        self.light_mode_switch2.update()
        self.value_r_s_entry.configure(state="disabled")
        self.value_r_s_entry.update()
        self.value_hr_s_entry.configure(state="disabled")
        self.value_hr_s_entry.update()
        self.value_fr_s_entry.configure(state="disabled")
        self.value_fr_s_entry.update()
        self.value_b_s_entry.configure(state="disabled")
        self.value_b_s_entry.update()
        self.value_w_s_entry.configure(state="disabled")
        self.value_w_s_entry.update()

        self.light_mode_switch3.configure(state="normal")
        self.light_mode_switch3.update()
        self.value_r_v_entry.configure(state="disabled")
        self.value_r_v_entry.update()
        self.value_hr_v_entry.configure(state="disabled")
        self.value_hr_v_entry.update()
        self.value_fr_v_entry.configure(state="disabled")
        self.value_fr_v_entry.update()
        self.value_b_v_entry.configure(state="disabled")
        self.value_b_v_entry.update()
        self.value_w_v_entry.configure(state="disabled")
        self.value_w_v_entry.update()

        self.light_mode_switch4.configure(state="normal")
        self.light_mode_switch4.update()
        self.value_r_f_entry.configure(state="disabled")
        self.value_r_f_entry.update()
        self.value_hr_f_entry.configure(state="disabled")
        self.value_hr_f_entry.update()
        self.value_fr_f_entry.configure(state="disabled")
        self.value_fr_f_entry.update()
        self.value_b_f_entry.configure(state="disabled")
        self.value_b_f_entry.update()
        self.value_w_f_entry.configure(state="disabled")
        self.value_w_f_entry.update()

        self.light_mode_switch5.configure(state="normal")
        self.light_mode_switch5.update()
        self.value_r_c_entry.configure(state="disabled")
        self.value_r_c_entry.update()
        self.value_hr_c_entry.configure(state="disabled")
        self.value_hr_c_entry.update()
        self.value_fr_c_entry.configure(state="disabled")
        self.value_fr_c_entry.update()
        self.value_b_c_entry.configure(state="disabled")
        self.value_b_c_entry.update()
        self.value_w_c_entry.configure(state="disabled")
        self.value_w_c_entry.update()

    if self.light_mode.get()=='2':
        self.light_mode_switch1.configure(state="normal")
        self.light_mode_switch1.update()
        self.value_r_g_entry.configure(state="disabled")
        self.value_r_g_entry.update()
        self.value_hr_g_entry.configure(state="disabled")
        self.value_hr_g_entry.update()
        self.value_fr_g_entry.configure(state="disabled")
        self.value_fr_g_entry.update()
        self.value_b_g_entry.configure(state="disabled")
        self.value_b_g_entry.update()
        self.value_w_g_entry.configure(state="disabled")
        self.value_w_g_entry.update()

        self.light_mode_switch3.configure(state="normal")
        self.light_mode_switch3.update()
        self.value_r_v_entry.configure(state="disabled")
        self.value_r_v_entry.update()
        self.value_hr_v_entry.configure(state="disabled")
        self.value_hr_v_entry.update()
        self.value_fr_v_entry.configure(state="disabled")
        self.value_fr_v_entry.update()
        self.value_b_v_entry.configure(state="disabled")
        self.value_b_v_entry.update()
        self.value_w_v_entry.configure(state="disabled")
        self.value_w_v_entry.update()

        self.light_mode_switch4.configure(state="normal")
        self.light_mode_switch4.update()
        self.value_r_f_entry.configure(state="disabled")
        self.value_r_f_entry.update()
        self.value_hr_f_entry.configure(state="disabled")
        self.value_hr_f_entry.update()
        self.value_fr_f_entry.configure(state="disabled")
        self.value_fr_f_entry.update()
        self.value_b_f_entry.configure(state="disabled")
        self.value_b_f_entry.update()
        self.value_w_f_entry.configure(state="disabled")
        self.value_w_f_entry.update()


def start_now(self,event):
    self.start_transmission()
    #transmission
def start_transmission(self):
    self.get_trans_value()
    print(self.light_mode.get())
    print(self.r)
    print(self.hr)
    print(self.fr)
    print(self.b)
    print(self.w)
    print(self.f)
    print("start PWM")
    red = math.trunc(2999 * ((self.r)/10.0))
    hred = math.trunc(2999 * ((self.hr)/10.0))
    fred = math.trunc(2999 * ((self.fr)/10.0))
    blue = math.trunc(2999 * ((self.b)/10.0))
    white = math.trunc(2999 * ((self.w)/10.0))
    self.fan = math.trunc(2999*((self.f)/10.0))

    self.servo.set_servo(4, red)
    self.servo.set_servo(14, blue)
    self.servo.set_servo(15, hred)
    self.servo.set_servo(17, white)
    self.servo.set_servo(18, fred)
    print( "r hr fr b w f", red, hred, fred, blue, white,self.fan)
    self.start_button_state=1
    self.loop = 1
    if self.set == 1:
        self.printtime_stop()
    if self.set == 0:
        pass

    #get transfer value
def get_trans_value(self):
    if self.light_mode.get()=='1':
        self.r = int(self.value_r_g.get())
        self.hr = int(self.value_hr_g.get())
        self.fr = int(self.value_fr_g.get())
        self.b = int(self.value_b_g.get())
        self.w = int(self.value_w_g.get())
    if self.light_mode.get()=='2':
        self.r = int(self.value_r_s.get())
        self.hr = int(self.value_hr_s.get())
        self.fr = int(self.value_fr_s.get())
        self.b = int(self.value_b_s.get())
        self.w = int(self.value_w_s.get())
    if self.light_mode.get()=='3':
        self.r = int(self.value_r_v.get())
        self.hr = int(self.value_hr_v.get())
        self.fr = int(self.value_fr_v.get())
        self.b = int(self.value_b_v.get())
        self.w = int(self.value_w_v.get())
    if self.light_mode.get()=='4':
        self.r = int(self.value_r_f.get())
        self.hr = int(self.value_hr_f.get())
        self.fr = int(self.value_fr_f.get())
        self.b = int(self.value_b_f.get())
        self.w = int(self.value_w_f.get())
    if self.light_mode.get()=='5':
        self.r = int(self.value_r_c.get())
        self.hr = int(self.value_hr_c.get())
        self.fr = int(self.value_fr_c.get())
        self.b = int(self.value_b_c.get())
        self.w = int(self.value_w_c.get())
    self.f = 10

    #update current time
def update_timeText(self):
    self.current = time.strftime("%H:%M:%S")
    # Update the timeText Label box with the current time
    self.timeText.configure(text = self.current)
    self.frameThread.after(1000, self.update_timeText)

    #compare time functions
def compare_start(self, event):
    self.printtime_start()
def compare_start_again(self):
    self.printtime_start()

def refresh_time_value(self):

    self.save_start_time_h.set(self.start_time_h.get())
    self.save_start_time_m.set(self.start_time_m.get())
    self.save_start_time_s.set(self.start_time_s.get())
    self.save_stop_time_h.set(self.stop_time_h.get())
    self.save_stop_time_m.set(self.stop_time_m.get())
    self.save_stop_time_s.set(self.stop_time_s.get())

    Label(text=":",width=2).grid(row=11, column=8)
    Label(text=":",width=2).grid(row=11, column=10)
    Label(text=":",width=2).grid(row=11, column=14)
    Label(text=":",width=2).grid(row=11, column=16)
    Label(text=" ",width=2).grid(row=11, column=12)
    Label(text=" ",width=2).grid(row=11, column=6)




def printtime_start(self):
    if self.start == 1:
        self.printstart()
    else:
        self.update_timeText()
        self.timestring = str(self.current)  
        if self.timestring[0]== self.save_start_time_h.get()[0] and self.timestring[1] == self.save_start_time_h.get()[1]:
            if self.timestring[3]== self.save_start_time_m.get()[0] and self.timestring[4] == self.save_start_time_m.get()[1]:
                if self.timestring[6]== self.save_start_time_s.get()[0] and self.timestring[7] == self.save_start_time_s.get()[1]:
                    self.start =1
                    print(self.timestring)
        self.frameThread.after(1000, self.printtime_start)

def printtime_stop(self):        
    if self.stop == 1:
        self.transmit_stop()
    else:
        self.time_cycle()
        self.loop += 1
        self.update_timeText()
        self.timestring = str(self.current)
        if self.timestring[0]== self.save_stop_time_h.get()[0] and self.timestring[1] == self.save_stop_time_h.get()[1]:
            if self.timestring[3]== self.save_stop_time_m.get()[0] and self.timestring[4] == self.save_stop_time_m.get()[1]:
                if self.timestring[6]== self.save_stop_time_s.get()[0] and self.timestring[7] == self.save_stop_time_s.get()[1]:
                    self.stop =1
                    print(self.timestring)
        self.frameThread.after(1000, self.printtime_stop)

#fan control function        
def time_cycle(self):
    if self.loop == 1:
       self.servo.set_servo(7, self.fan) 
    if self.loop < 11:
        pass
    if self.loop == 11:
        self.servo.set_servo(7, 0)
    if self.loop > 11 and self.loop < 61:
        pass
    if self.loop == 61:
        self.loop = 0

def printstart(self):
    self.start=0
    print("start")
    self.start_transmission()

#modify this when come back
def set_time(self,event):
    self.refresh_time_value()
    if self.start_button_state == 1:
        if self.set == 0:
            self.printtime_stop()
            self.set=1
        if self.set == 1:
            pass
    if self.start_button_state == 0:
        self.compare_start_again()
        self.set=1

def transmit_stop(self):
    self.stop = 0
    print("stop")
    self.servo.set_servo(4, 0)
    self.servo.set_servo(14, 0)
    self.servo.set_servo(15, 0)
    self.servo.set_servo(17, 0)
    self.servo.set_servo(18, 0)
    self.servo.set_servo(7, 0)
    print("done")
    self.start_button_state = 0
    self.compare_start_again()

def save_setting(self,event):
    self.settings = [int(self.value_r_g.get()),int(self.value_hr_g.get()),
                        int(self.value_fr_g.get()),int(self.value_b_g.get()),
                        int(self.value_w_g.get()),#germination
                        int(self.value_r_s.get()),int(self.value_hr_s.get()),
                        int(self.value_fr_s.get()),int(self.value_b_s.get()),
                        int(self.value_w_s.get()),#seedling
                        int(self.value_r_v.get()),int(self.value_hr_v.get()),
                        int(self.value_fr_v.get()),int(self.value_b_v.get()),
                        int(self.value_w_v.get()),#vegetative
                        int(self.value_r_f.get()),int(self.value_hr_f.get()),
                        int(self.value_fr_f.get()),int(self.value_b_f.get()),
                        int(self.value_w_f.get()),#flowering
                        int(self.value_r_c.get()),int(self.value_hr_c.get()),
                        int(self.value_fr_c.get()),int(self.value_b_c.get()),
                        int(self.value_w_c.get()),#custom
                        int(self.start_time_h.get()),int(self.start_time_m.get()),
                        int(self.start_time_s.get()),#starttime
                        int(self.stop_time_h.get()),int(self.stop_time_m.get()),
                        int(self.stop_time_s.get())]#stoptime
    sname = asksaveasfilename(defaultextension=".pickle",filetypes=(("PICKLE files", "*.pickle"),
                                       ("All files", "*.*") ))
    self.save_button.config(relief = 'raised')
    if sname:
        self.myfile = open(sname,'wb')
        pickle.dump(self.settings,self.myfile)
        self.myfile.close()

def read_setting(self,event):
    fname = askopenfilename(filetypes=(("PIKLE files", "*.pickle"),
                                       ("All files", "*.*")))
    if fname:
        self.myfile = open(fname,'rb')
        self.settings = pickle.load(self.myfile)
        self.load_setting()
        self.myfile.close()

def load_setting(self):
    #germination
    self.value_r_g.set(self.settings[0])
    self.value_hr_g.set(self.settings[1])
    self.value_fr_g.set(self.settings[2])
    self.value_b_g.set(self.settings[3])
    self.value_w_g.set(self.settings[4])
    #seedling
    self.value_r_s.set(self.settings[5])
    self.value_hr_s.set(self.settings[6])
    self.value_fr_s.set(self.settings[7])
    self.value_b_s.set(self.settings[8])
    self.value_w_s.set(self.settings[9])
    #vegetative
    self.value_r_v.set(self.settings[10])
    self.value_hr_v.set(self.settings[11])
    self.value_fr_v.set(self.settings[12])
    self.value_b_v.set(self.settings[13])
    self.value_w_v.set(self.settings[14])
    #flowering
    self.value_r_f.set(self.settings[15])
    self.value_hr_f.set(self.settings[16])
    self.value_fr_f.set(self.settings[17])
    self.value_b_f.set(self.settings[18])
    self.value_w_f.set(self.settings[19])
    #custom
    self.value_r_c.set(self.settings[20])
    self.value_hr_c.set(self.settings[21])
    self.value_fr_c.set(self.settings[22])
    self.value_b_c.set(self.settings[23])
    self.value_w_c.set(self.settings[24])
    #starttime
    self.start_time_h.set(self.settings[25])
    self.start_time_m.set(self.settings[26])
    self.start_time_s.set(self.settings[27])
    #stoptime
    self.stop_time_h.set(self.settings[28])
    self.stop_time_m.set(self.settings[29])
    self.stop_time_s.set(self.settings[30])

def main():
    ex = LEDChooser()

if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:0)

不知道原因,但尝试在不同于零的DMA通道上设置RPIO

self.servo = PWM.Servo(10, 3000, 1)

它对我有用。