启动时py2app应用程序错误

时间:2018-06-12 15:37:37

标签: python python-3.x macos tkinter py2app

我已经创建了一个充当待办事项列表的python脚本。我正在使用python 3,我正在使用tkinter作为我的UI。

我没有遇到使用py2app导出程序的问题,但是当我运行它时,我得到了to_do_list ERROR,带有Console的选项,或者终止。

脚本可以创建窗口,但发生错误时窗口为空白。

我认为这与tkinter有关,因为我在创建prints("Hello World")的脚本时没有收到错误。

当我从终端中的python3 to_do_list.py运行脚本时,脚本运行正常。 这与我的代码有关吗?

我已经发布了以下代码:

try:
    # for Python2
    from Tkinter import *   ## notice capitalized T in Tkinter 
except ImportError:
    # for Python3
    from tkinter import *   ## notice lowercase 't' in tkinter here

import datetime

#Alarms Functions
alarms = []
class alarm:

        def __init__(self, name, time, pos):
                self.name = name

                try:
                        self.time = int(float(time))
                except:
                        pass





                self.label = Label(window, text=self.name, bg="black", fg="white", font = "none 12 bold")
                self.label.grid(row=pos, column=1, sticky=W)

                self.timeLabel = Label(window, text=self.time, bg="black", fg="white", font = "none 12 bold")
                self.timeLabel.grid(row=pos, column=2, sticky=E)

                self.deleteButton= Button(window, text="delete alarm", command = lambda: deleteAlarm(self))
                self.deleteButton.grid(row=pos, column=3, sticky=W)

        def deleteWidgets(self) :
                self.label.destroy()
                self.timeLabel.destroy()
                self.deleteButton.destroy()

        def updateWidgets(self, pos) :
                self.deleteWidgets()

                self.label = Label(window, text=self.name, bg="black", fg="white", font = "none 12 bold")
                self.label.grid(row=pos, column=1, sticky=W)

                self.timeLabel = Label(window, text=self.time, bg="black", fg="white", font = "none 12 bold")
                self.timeLabel.grid(row=pos, column=2, sticky=E)

                self.deleteButton= Button(window, text="delete alarm", command = lambda: deleteAlarm(self))
                self.deleteButton.grid(row=pos, column=3, sticky=W)




def deleteAlarm(alarm) :
        alarm.deleteWidgets()
        alarms.remove(alarm)

def updateAlarms() :
        count=0
        for alarm in alarms:
                alarm.updateWidgets(count+8)
                count+=1

def addAlarm() :
        entered_text=reminderEntry.get()
        entered_time=timeEntry.get()
        reminderEntry.delete(0,END)
        timeEntry.delete(0,END)

        alarms.append(alarm(entered_text, entered_time, len(alarms))) #Add alarm to list of alarms
        updateAlarms() #update the alarms



#ToDo list functions
toDoItems = {}

def addTaskButton(toDo, buttonPos):
        toDoItems[toDo] = Button(window, text=toDo, command= lambda: deleteTaskButton(toDo) )
        toDoItems[toDo]. grid(row=buttonPos, column=0, sticky=W)

def updateTaskButtons() :
        #We need to create a system that deletes all the buttons and puts new ones. 
        try:
                for task in toDoItems.keys() :
                        toDoItems[task].destroy()
                        toDoItems[task] = None
        except:
                #It should do this every time, at least once
                pass

        counter = 0;
        for task in toDoItems.keys() :
                addTaskButton(task, counter+7)
                counter+=1


def deleteTaskButton(toDo):
        toDoItems[toDo].destroy() # Delete Button
        del toDoItems[toDo] #Delete Dictionary Item
        updateTaskButtons() #Update the rest of the buttons

def enterTask():
    entered_text=textEntry.get ()
    textEntry.delete(0, END) #This also works with the outbut box, aka Text boxes. 
    toDoItems[entered_text]=None
    updateTaskButtons()


##### main:
window = Tk()
window.title("The Work Management System")
window.configure(background="black")

##### My Photo
photo1 = PhotoImage(file="photo1.png")
Label (window, image=photo1, bg="black") . grid(row=1, column=0, sticky=E)

Label (window, text="Welcome to the Work Managment System", bg="black", fg="white", font="none 16 bold") .grid(row=0, column = 0, sticky=N)

#ToDo list entry
Label (window, text="Enter specific tasks in the text box below:", bg="black", fg="white", font="none 12 bold") . grid(row=2, column = 0, sticky=W)

textEntry = Entry(window, width=20, bg="white") #Text Entry
textEntry.grid(row=3, column=0, sticky=W)

Button(window, text="Add Task", width=8, command=enterTask) .grid(row=4, column=0, sticky=W) #Submit button for ToDo list.

Label(window, text="\nTasks: ", bg="black", fg="white", font="none 12 bold") .grid(row=5, column = 0, sticky=W)
Label(window, text="Click on Tasks when Done ", bg="black", fg="white", font="none 10 italic") .grid(row=6, column = 0, sticky=W)


#Scheduled Remiders list entry
Label (window, text="Enter specific tasks in the text box below:", bg="black", fg="white", font="none 12 bold") . grid(row=2, column = 1, sticky=W)

reminderEntry = Entry(window, width=20, bg="white") #Text Entry
reminderEntry.grid(row=3, column=1, sticky=W)

Label (window, text="Enter specific time for the alarm:", bg="black", fg="white", font="none 12 bold") . grid(row=4, column = 1, sticky=W)

timeEntry = Entry(window, width=20, bg="white") #Text Entry
timeEntry.grid(row=5, column=1, sticky=W)

Button(window, text="Add Alarm", command=addAlarm ) .grid(row=6, column=1, sticky=W) #Submit button for ToDo list.

Label(window, text="\nAlarms: ", bg="black", fg="white", font="none 12 bold") .grid(row=7, column = 1, sticky=W)
Label(window, text="\nTime: ", bg="black", fg="white", font="none 12 bold") .grid(row=7, column = 2, sticky=W)


window.geometry("1500x1000")
#####run the main loop
window.mainloop()

0 个答案:

没有答案