0

I am making a To-Do List for fun and I'm having troubles with bringing lists to different functions. The goal of the program is that the user presses the "New Task" button and inputs something and then the string is added to the list, then shown via Listbox. Here is what I have so far.

P.S Ignore the DelTask function as that is still WIP

from Tkinter import *
import Tkinter
import tkMessageBox
import sys

count = 0

class ToDoList:

def __init__(self):

    #print testlist


    self._count = 0
    self.main_window = Tkinter.Tk()

    #size   
    self.main_window.minsize(1000,800)
    self.main_window.maxsize(1000,800)

    #frames
    self.title_frame = Tkinter.Frame(self.main_window)
    #self.side_frame = Tkinter.Frame(self.main_window)

    #labels
    self.title = Tkinter.Label(self.title_frame, text = 'To Do List', font = ("Purisa",30))
    self.title2 = Tkinter.Label(self.title_frame, text = 'By Kevin', font = ("Purisa",15))

    #buttons
    self.newtask_button = Tkinter.Button(self.main_window, text='New Task', command = self.NewTask, width=20)
    self.newtask_button.grid()

    self.deltask_button = Tkinter.Button(self.main_window, text='Delete Task', command = self.DelTask, width=20)
    self.deltask_button.grid()




    #execute
    self.title.pack(side='top')
    self.title2.pack(side='top')
    self.title_frame.pack(side='top')
    self.newtask_button.pack(padx=4, pady=4)
    self.deltask_button.pack(padx=1, pady=1)

    #list stuff
    listbox = Listbox(self.main_window, width=100, height = 100, font=('Fixed',20) )
    listbox.pack()


    #print testlist


    Tkinter.mainloop()

def NewTask(self):
    self.newtask_window = Tkinter.Tk()


    self.newtask_window.minsize(250,150)
    self.newtask_window.maxsize(250,150)

    #text
    self.task_label = Tkinter.Label(self.newtask_window, text='Enter Task.')
    self.task_label.pack()

    #entry
    self.task_entry = Tkinter.Entry(self.newtask_window, width=30)
    self.task_entry.pack()


    #button
    self.task_button = Tkinter.Button(self.newtask_window, text='Ok', command = self.NewTaskCount, width = 20)
    self.task_button.pack()


    Tkinter.mainloop()

def NewTaskCount(self):
    listbox = Listbox(self.main_window, width=100, height = 100, font=('Fixed',20) )
    listbox.pack()
    self._count += 1
    self.newtask_window.destroy()

def DelTask(self):
    tkMessageBox.showinfo('Title', 'Task Deleted')

 program = ToDoList()

1 Answer 1

1

You're using Tkinter incorrectly. You should always create exactly one instance of the Tk class and call mainloop exactly once during the life of your program. If you want multiple windows, after creating the instance of Tk, any other windows need to be an instance of Toplevel.

Sign up to request clarification or add additional context in comments.

3 Comments

How would you go about doing that to replace the Tk()?
@user1840752: like I said in my answer, create instances of Toplevel if you need more than one window.
how would I be able to pass the list into the TopLevel?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.