如何使这个python代码在raspberry pi上运行

时间:2017-02-15 13:47:55

标签: python linux tkinter raspberry-pi pycharm

我写了这段代码,它在我的Windows PC上使用PyCharm完美运行。 当我使用默认解释器从我的覆盆子pi 2运行它时,它的行为很奇怪 - 按钮并不总是响应,并且alarmList数组将无法在命令上正确打印。

以前有人遇到过这个问题吗?

代码:

import time
from Tkinter import *
import tkMessageBox

date = [time.strftime('%Y', time.localtime(time.time())), time.strftime('%m', time.localtime(time.time())), time.strftime('%d', time.localtime(time.time())), time.strftime('%H', time.localtime(time.time())), time.strftime('%M', time.localtime(time.time())), time.strftime('%S', time.localtime(time.time()))]

main = Tk()
main.overrideredirect(True)
main.grid_columnconfigure(0, weight=3)
main.grid_rowconfigure(0, weight=3)
main.geometry("{0}x{1}+0+0".format(main.winfo_screenwidth(), main.winfo_screenheight()))

AlarmList = []

def setAlarm():
    def submit_alarm():
        get_alarm = [int(alarm_hour_entry.get()), int(alarm_minute_entry.get())]
        alarm_hour_entry.delete(0, END)
        alarm_minute_entry.delete(0, END)
        if get_alarm[0] > 0 and get_alarm[0] < 23 and get_alarm[1] >= 0 and get_alarm[1] < 59:
            AlarmList.append(get_alarm)
            AlarmList.sort()
        else:
            tkMessageBox.showinfo("Invalid Time", "please enter a valid time, you fucking douchebag")
        print AlarmList

    alarm_set = Tk()
#   alarm_set.configure(bg='white')
    alarm_set.overrideredirect(True)
    alarm_set.geometry("{0}x{1}+0+0".format(alarm_set.winfo_screenwidth(), alarm_set.winfo_screenheight()))

    alarm_hour_label = Label(alarm_set, text="Alarm Hour:")
    alarm_hour_entry = Entry(alarm_set)
    alarm_hour_label.grid(row=0, column=0)
    alarm_hour_entry.grid(row=0, column=1)

    alarm_minute_label = Label(alarm_set, text="Alarm Minute:")
    alarm_minute_entry = Entry(alarm_set)
    alarm_minute_label.grid(row=1, column=0)
    alarm_minute_entry.grid(row=1, column=1)

    submit_button = Button(alarm_set, text='submit', command=submit_alarm)
    submit_button.grid(row=2, column=1)

    quit_alarm = Button(alarm_set, text="back to menu", command=alarm_set.destroy)
    quit_alarm.grid(row=2, column=0)

    alarm_set.mainloop()

def tick():
    global time1
    # get the current local time from the PC
    time2 = time.strftime('%H:%M:%S')
    # if time string has changed, update it
    if time2 != time1:
        time1 = time2
        clock.config(text=time2)
    # calls itself every 200 milliseconds
    # to update the time display as needed
    # could use >200 ms, but display gets jerky
    clock.after(200, tick)

button1=Button(text='Set Alarm', font=('times', 15, 'bold'), command=setAlarm, bd=0, padx=2, pady=2)
button1.config(height=10, width=50)
button1.grid(row=0, column=0, sticky=W)

quit_main=Button(main, text='quit', font=('times', 15, 'bold'), command=main.destroy, bd=0, padx=30, pady=2)
#quit_main.configure(height=10, width=20)
quit_main.grid(row=3, column=0, sticky=W)

time1 = ''
clock = Label(main, font=('times', 100, 'bold'), bg='blue', fg='white')
clock.grid(row=1, columnspan=2, sticky=N)

settings_photo=PhotoImage(file="settings.gif")
settings=Button(image=settings_photo,bd=0)
settings.grid(row=3, column=1)

tick()

main.mainloop()

0 个答案:

没有答案