How do I access a label to change its text in Tkinter - python

I am trying to change the Label's text, but I have no idea how to access it. I have added the label and a button and I want to change the label's text on button click. However, I cannot access the label from the function - see the line with the question marks. What should I change it to?
When I try the code as is I get "Example instance has no attribute 'frame2'"
I am using Python 2.7
============== update =========
changed frame2 to self.frame2, but it did not solve the problem
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.all = []
self.path = ""
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("SomeName")
self.style = Style()
self.style.theme_use("default")
self.frame2 = Frame(self, relief=FLAT, borderwidth=2)
self.frame2.pack(side=TOP, fill=BOTH, expand=False)
# this is my label
usrLable = Label(self.frame2, text="Username: ")
usrLable.pack(side=LEFT, padx=5, pady=1)
frame6 = Frame(self, relief=FLAT, borderwidth=2)
frame6.pack(fill=BOTH, expand=True)
# this is my button
stopButton = Button(frame6, text="Stop", command=self.stopButtonClick)
stopButton.pack(side=LEFT)
def stopButtonClick(self):
try:
self.frame2.usrLable.configure(text="hello") # ?????????????
except Exception,e:
print str(e)
return

You need to replace the following line:
frame2 = Frame(self, relief=FLAT, borderwidth=2)
frame2.pack(side=TOP, fill=BOTH, expand=False)
with:
self.frame2 = Frame(self, relief=FLAT, borderwidth=2)
self.frame2.pack(side=TOP, fill=BOTH, expand=False)
to make frame2 an instance attribute instead of local variable.
And also change the references to frame2 to self.frame2 accordingly.
Same for the usrLable.
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.all = []
self.path = ""
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("SomeName")
self.style = Style()
self.style.theme_use("default")
self.frame2 = Frame(self, relief=FLAT, borderwidth=2)
self.frame2.pack(side=TOP, fill=BOTH, expand=False)
self.usrLable = Label(self.frame2, text="Username: ")
self.usrLable.pack(side=LEFT, padx=5, pady=1)
self.frame6 = Frame(self, relief=FLAT, borderwidth=2)
self.frame6.pack(fill=BOTH, expand=True)
stopButton = Button(self.frame6, text="Stop", command=self.stopButtonClick)
stopButton.pack(side=LEFT)
def stopButtonClick(self):
self.usrLable.configure(text="hello")

Related

Frame inside A OOP Tkinter Frame

Right so I am trying to put a frame into the waiter page to split it into different frames
like this design but nothings working.
This is the design:
I've tried to create a basic Frame inside but it doesn't appear.
The Frame that I created doesnt throw an error however it might be in a different position, So I attempted to move it but it didn't change anything and just didn't display it on the WaiterPage.
Note There is no validation for the login so just click login after choosing WaiterPage.
import tkinter as tk
from tkinter import SUNKEN, Label, ttk
from tkinter import IntVar
from tkinter.constants import BOTH, BOTTOM, CENTER, GROOVE, LEFT, RIGHT
from typing import Container
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self,*args,**kwargs)
self.bg = tk.PhotoImage(file="D:/talha\Documents\Projects For Portfolio\Some Fun\CourseWork\Testbg.png")
container = tk.Frame(self)
self.geometry("800x500")
self.resizable(False,False)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for page in (ManagerPage, WaiterPage, Login):
frame = page(container,self)
self.frames[page] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(page)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class WaiterPage(tk.Frame):
def __init__(self, parent, controller):
MainFrame = tk.Frame.__init__(self, parent)
RightFrame = tk.Frame(MainFrame, background='blue')
class ManagerPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Label(self, text="Manager Page:").pack()
LeftFrame = tk.Frame(self)
LeftFrame.pack(side=LEFT)
CurrentTables = tk.Listbox(LeftFrame, width=70,height=33).pack(side=LEFT,fill=BOTH)
AddTable = ttk.Button(self, text="Add Table").place(width=160,height=37,relx=0.65, rely=0.5, anchor=CENTER)
AddBooking = ttk.Button(self, text="Add Booking").place(width=160,height=37,relx=0.875, rely=0.5, anchor=CENTER)
ViewBooking = ttk.Button(self, text="View Booking").place(width=160, height=37,relx=0.65, rely=0.65, anchor=CENTER)
Collection = ttk.Button(self, text="Collection").place(width=160,height=37,relx=0.875, rely=0.65, anchor=CENTER)
Inventory = ttk.Button(self, text="View Inventory").place(width=160,height=37,relx=0.75, rely=0.8, anchor=CENTER)
Exit = ttk.Button(self, text="Exit").place(width=160,height=37,relx=0.75, rely=0.9, anchor=CENTER)
class Login(tk.Frame):
def __init__(self, parent, controller):
def CallBack():
if ManagerValue.get() == 1:
WaiterCheck.configure(state='disabled')
if WaiterValue.get() == 1:
ManagerCheck.configure(state='disabled')
if ManagerValue.get() == 0:
WaiterCheck.configure(state='normal')
if WaiterValue.get() == 0:
ManagerCheck.configure(state='normal')
def CheckPage():
if ManagerValue.get() == 1:
self.controller.show_frame(ManagerPage)
if WaiterValue.get() == 1:
self.controller.show_frame(WaiterPage)
tk.Frame.__init__(self,parent)
self.controller = controller
label_bkgr = tk.Label(self, image=self.controller.bg)
label_bkgr.place(relx=0.5, rely=0.5, anchor=CENTER)
tk.Label(self, text="Username: ",font=("Segoe UI", 12),bg='#59C8E3').place(relx=0.3, rely=0.35, anchor=CENTER)
tk.Label(self, text="Password: ",font=("Segoe UI", 12),bg='#59C8E3').place(relx=0.3, rely=0.45, anchor=CENTER)
ManagerValue = IntVar()
WaiterValue = IntVar()
ManagerCheck = tk.Checkbutton(self, text="Manager",variable=ManagerValue,command=CallBack,font=("Segoe UI", 12),bg='#59C8E3',activebackground='#59C8E3')
ManagerCheck.place(relx=0.43, rely=0.535, anchor=CENTER)
WaiterCheck = tk.Checkbutton(self, text="Waiter",variable=WaiterValue,command=CallBack,font=("Segoe UI", 12),bg='#59C8E3',activebackground='#59C8E3')
WaiterCheck.place(relx=0.59, rely=0.535, anchor=CENTER)
UserEntry = ttk.Entry(self)
UserEntry.place(width=160,
height=37,relx=0.5, rely=0.35, anchor=CENTER)
PassEntry = ttk.Entry(self)
PassEntry.configure(show="*")
PassEntry.place(width=160,
height=37,relx=0.5, rely=0.45, anchor=CENTER)
Submit = ttk.Button(self, text="Submit",command=CheckPage)
Submit.place(width=160,
height=37,relx=0.5, rely=0.6, anchor=CENTER)
app = App()
app.mainloop()
The first problem is that you never call pack or grid on RightFrame, so it will never appear.
The second problem is that RightFrame needs to be a child of self because MainFrame is None.
class WaiterPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
RightFrame = tk.Frame(self, background='blue')
RightFrame.pack(fill="both", expand=True)
I don't know if pack(fill="both", expand=True) are the right options, but the point is you have to call pack or grid or place on the frame in order for it to be visible.

How to prevent multiple windows from popping up in tkinter?

import tkinter as tk
from tkinter import *
from tkinter import ttk
LARGE_FONT = ("Verdana", 12)
class pages(tk.Tk):
#starts us off in the login page
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "ScanNET")
tk.Tk.wm_minsize(self, 800, 800)
container = tk.Frame(self)
container.pack(side=TOP, fill=BOTH, expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (loginpage, GUI):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky=N+E+S+W)
self.show_frame(loginpage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class loginpage(tk.Frame):
#login page content
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
loginlabel = tk.Label(self, text="login page", font=LARGE_FONT)
loginlabel.pack(padx=10, pady=10)
#button moves you to gui
loginbutton1 = tk.Button(self, text= "Go to GUI", command=lambda: controller.show_frame(GUI))
loginbutton1.pack()
class GUI(tk.Frame):
def __init__(self, parent, controller):
#all widths and heights aren't official, most likely change
tk.Frame.__init__(self, parent)
self.root = tk.Tk()
#the tabs
my_notebook = ttk.Notebook(self.root)
my_notebook.pack()
devicestab = Frame(my_notebook, width=800, height=600)
reportstab = Frame(my_notebook, width=800, height=600)
devicestab.pack(fill=BOTH, expand=1)
reportstab.pack(fill=BOTH, expand=1)
my_notebook.add(devicestab, text="Devices")
my_notebook.add(reportstab, text="Reports")
#contents for devices tab
devicesleft = LabelFrame(devicestab, text="Devices found: ", padx=5, pady=5, width=500, height=600)
devicesleft.grid(row=0, column=0)
devicesright = LabelFrame(devicestab, text="Activity Feed: ", padx=5, pady=5, width=300 , height=600)
devicesright.grid(row=0, column=1)
#contents for reports tab
reportsleft = LabelFrame(reportstab, text="Report Summaries: ", padx=5, pady=5, width=400 , height=600)
reportsleft.grid(row=0, column=0)
reportsright= LabelFrame(reportstab, text="Charts and Diagrams: ", padx=5, pady=5, width=400 , height=600)
reportsright.grid(row=0, column=1)
app = pages()
app.mainloop()
When I run this, both the loginpage and GUI windows open. Correct me if I'm wrong, but I think the problem is probably around the
tk.Frame.__init__(self, parent)
self.root = tk.Tk()
my_notebook = ttk.Notebook(self.root)
part in the GUI class. I've searched everywhere and I can't seem to find a way to have a first page as a login page which will move to a second page that has tabs using notebook. I feel as if something else has to be in the ttk.Notebook() part, and perhaps remove self.root = tk.Tk() after. I'd love to hear what y'all think.
I am assuming you want the notebook in the same widget of the rest, so you should not use tk.Tk() and then you place the notebook in the parent which is already your root. Check the code in the end of my answer. Also, since there was a lot of problems with your code I made some changes and comments that will help you to write better codes in tkinter. Please read it carefully. You may also want to study the effbot web page.
import tkinter as tk
# from tkinter import * # just don't do this
from tkinter import ttk
LARGE_FONT = ("Verdana", 12)
# class pages(tk.Tk):
class Pages(tk.Tk): # class names should start with upper case
#starts us off in the login page
# def __init__(self, *args, **kwargs):
def __init__(self):
# tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.__init__(self)
# tk.Tk.wm_title(self, "ScanNET")
self.winfo_toplevel().title("ScanNET")
# tk.Tk.wm_minsize(self, 800, 800)
self.wm_minsize(800, 800) # since you defined tk.Tk as pages parent you can call Tk methods directly
container = tk.Frame(self)
# container.pack(side=TOP, fill=BOTH, expand=True)
# container.grid_rowconfigure(0, weight=1)
# container.grid_columnconfigure(0, weight=1)
container.grid(row=0, column = 0) # don't use pack if you want to use grid
self.frames = {}
for F in (loginpage, GUI):
frame = F(container, self)
self.frames[F] = frame
# frame.grid(row=0, column=0, sticky=N+E+S+W)
frame.grid(row=0, column=0, sticky='NESW') #since we are not importing all we are not importing tk.W but you can use string instead
self.show_frame(loginpage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class loginpage(tk.Frame):
#login page content
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
loginlabel = tk.Label(self, text="login page", font=LARGE_FONT)
loginlabel.pack(padx=10, pady=10)
#button moves you to gui
loginbutton1 = tk.Button(self, text= "Go to GUI", command=lambda: controller.show_frame(GUI))
loginbutton1.pack()
class GUI(tk.Frame):
def __init__(self, parent, controller):
#all widths and heights aren't official, most likely change
tk.Frame.__init__(self, parent)
# self.root = tk.Tk() # don't create new Tk objects, you just need one. The others should be Toplevel objects
### self.root = tk.Toplevel() ### this would be the correct way of creating a new window but you don't want to do that here your root is your parent
#the tabs
# my_notebook = ttk.Notebook(self.root)
my_notebook = ttk.Notebook(self) # this is how you place the notebook in the Frame widget and not in a new one
# my_notebook.pack()
my_notebook.grid() # we are now using grid so it will not accept pack anymore
# devicestab = Frame(my_notebook, width=800, height=600)
devicestab = tk.Frame(my_notebook, width=800, height=600) # again, since we are not importing al we have to use tk. before tkinter methods
# reportstab = Frame(my_notebook, width=800, height=600)
reportstab = tk.Frame(my_notebook, width=800, height=600)
# devicestab.pack(fill=BOTH, expand=1)
devicestab.pack(fill="both", expand=1) # instead of tk.BOTH we can use "both"
reportstab.pack(fill="both", expand=1)
my_notebook.add(devicestab, text="Devices")
my_notebook.add(reportstab, text="Reports")
#contents for devices tab
devicesleft = tk.LabelFrame(devicestab, text="Devices found: ", padx=5, pady=5, width=500, height=600)
devicesleft.grid(row=0, column=0)
devicesright = tk.LabelFrame(devicestab, text="Activity Feed: ", padx=5, pady=5, width=300 , height=600)
devicesright.grid(row=0, column=1)
#contents for reports tab
reportsleft = tk.LabelFrame(reportstab, text="Report Summaries: ", padx=5, pady=5, width=400 , height=600)
reportsleft.grid(row=0, column=0)
reportsright= tk.LabelFrame(reportstab, text="Charts and Diagrams: ", padx=5, pady=5, width=400 , height=600)
reportsright.grid(row=0, column=1)
app = Pages()
app.mainloop()

How to locate tkinter root window to destroy?

For my current project with tkinter I was in the need of having multiple pages in my GUI and was able to achieve this through the answer I have linked to here Switch between two frames in tkinter.
However, I can't find a way to implement a call to a root window without ruining this preexisting code. I am trying to create a widget button to destroy the root window but I can't locate the specific root to destroy.
from tkinter import *
class MainApp(Tk):
"""Class that displays respective frame"""
def __init__(self):
Tk.__init__(self)
self.winfo_toplevel().title("YouTube Ripper and Editor")
self.resizable(0, 0)
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, Downloader, Audio_Player, Config, About):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="NSEW")
self.show_frame("StartPage")
def show_frame(self, page_name):
"""Raise called frame"""
frame = self.frames[page_name]
frame.tkraise()
class StartPage(Frame):
"""Class that contains the start page"""
def __init__(self, parent, controller):
Frame.__init__(self, parent)
self.configure(bg = f_color)
self.controller = controller
b_font = Font(family = "Franklin Gothic Book", size = 12)
titleLabel = Label(self, text="Youtube Ripper and Editor", font = ("Franklin Gothic Book", 16, "bold"), bg = f_color)
titleLabel.pack(side="top", fill="x", pady= 30)
button1 = Button(self, text="Downloader", command=lambda: controller.show_frame("Downloader"),
font = b_font, bg = b_color, activebackground = bp_color)
button2 = Button(self, text="Audio Player", command=lambda: controller.show_frame("Audio_Player"),
font = b_font, bg = b_color, activebackground = bp_color)
button3 = Button(self, text="MP3 Configurator", command=lambda: controller.show_frame("Config"),
font = b_font, bg = b_color, activebackground = bp_color)
button4 = Button(self, text="About", command=lambda: controller.show_frame("About"),
font = b_font, bg = b_color, activebackground = bp_color)
button5 = Button(self, text="Exit", command=self.exit, font = b_font, bg = b_color, activebackground = bp_color)
# button1.pack(fill = 'x')
# button2.pack(fill = 'x')
# button3.pack(fill = 'x')
# button4.pack(fill = 'x')
button5.pack(fill = 'x')
def exit(self):
"""Exit program"""
MainApp.destroy()
def main():
app = MainApp()
app.mainloop()
main()
Use the reference to the root window that you have saved in StartPage's __init__, and call destroy on that
def exit(self):
"""Exit program"""
self.controller.destroy()

Layout Problems with Tkinter

I have a problem regarding the layout in tkinter. This is the
Layout I want to have and this is whatI have right now.
I am not understanding why this is happening. I thought when I specify the width and height for a specific frame it would take all this place but this is not happening looking at self.GameStatFrame. It would be nice if someone could explain to me why code does what it does and what my mistakes were.
Here is the code:
class Application(tk.Frame):
def __init__(self, parent):
self.parent = parent
tk.Frame.__init__(self, parent)
#self.update_idletasks()
self.createWidgets()
def createWidgets(self):
#new frame for everything not in the canvas
#self.Frame = tk.Frame(self.parent)
self.MlGameStatFrame = tk.Frame(self.parent, width=600, height=300,
bg='blue')
self.GameStatFrame = tk.Frame(self.MlGameStatFrame, bg='white',
width=300, height=300)
self.MlFrame = tk.Frame(self.MlGameStatFrame, bg='white',
width=300, height=300)
#self.Frame.pack()
self.createGraphWidget()
self.MlGameStatFrame.pack()
self.GameStatFrame.pack(side=tk.LEFT, anchor=tk.W, fill=tk.BOTH)
self.MlFrame.pack(side=tk.BOTTOM, fill=tk.BOTH)
self.createGameStats(self.GameStatFrame)
self.createMlStats(self.MlFrame)
#self.createLog()
def createGraphWidget(self):
self.graph = tk.Canvas(self.parent, background ='white',
width=200,height=300)
self.graph.create_rectangle(0,20,40,50)
self.graph.pack(side=tk.TOP,fill=tk.X)
# needs to get a frame because side by side with Ml stats
def createGameStats(self,GameFrame):
Frame1 = tk.Frame(GameFrame, bg='red', width=300)
tk.Label(Frame1, text="Status: ").pack(side=tk.LEFT, expand=tk.YES)
#initialize with certain value for now
self.statusChange = tk.Label(Frame1,
text="Learning").pack(side=tk.LEFT, expand=tk.YES)
Frame2=tk.Frame(GameFrame, bg='green')
tk.Label(Frame2, text="Fitness").pack(side=tk.LEFT, expand=tk.YES,
anchor=tk.W) #could get changed
self.fitnessChange = tk.Label(Frame2, text="6").pack(side=tk.LEFT,
expand=tk.YES)
Frame1.pack(side=tk.TOP, anchor=tk.W)
Frame2.pack(side=tk.TOP,fill=tk.X, anchor=tk.W)
def createMlStats(self, MlFrame):
Frame1 = tk.Frame(MlFrame)
tk.Label(Frame1, text="Status: ").pack(side=tk.LEFT, expand=tk.YES)
# initialize with certain value for now
self.statusChange = tk.Label(Frame1,
text="Learning").pack(side=tk.LEFT, fill=tk.X, expand=tk.YES)
Frame2=tk.Frame(MlFrame)
tk.Label(Frame2, text="Fitness").pack(expand=tk.YES, anchor=tk.W)
self.fitnessChange = tk.Label(Frame2, text="6").pack(side=tk.LEFT,
fill=tk.X, expand=tk.YES)
Frame1.pack(side=tk.TOP, fill=tk.BOTH,anchor=tk.W)
Frame2.pack(side=tk.TOP,fill=tk.BOTH)
def main():
root = tk.Tk()
root.geometry('600x900-0+0') #120* 50 ppixels in top right corner of desktop
app = Application(root)
app.master.title('Sample application')
app.mainloop()
if __name__ == '__main__':
main()
The .grid layout manager is much more flexible:
class Application(Frame):
def __init__(self, parent):
self.parent = parent
Frame.__init__(self, parent)
self.create_widgets()
def create_widgets(self):
graph = Canvas(self.parent, width=200, height=300, bg="white")
graph.create_rectangle(0, 20, 40, 50)
mlgamestat_frame = Frame(self.parent, width=600, height=300, bg="blue")
gamestat_frame = Frame(mlgamestat_frame, width=300, height=300, bg="yellow")
ml_frame = Frame(mlgamestat_frame, width=300, height=300, bg="green")
graph.grid(row=0, column=0)
mlgamestat_frame.grid(row=1, column=0)
gamestat_frame.grid(row=0, column=0)
ml_frame.grid(row=0, column=1)
You can place widgets as if they were in a table. The code above makes your intended layout.

How do I remove a checkbutton when it is checked

I have built a simple to-do list and I am trying to get the checkbox to remove itself when it is checked(to signify that the task has been completed)
I am not sure how I need to be implementing the function in order to remove itself. Can anyone help me out with this. I've combed through a list of pages and none of them have really indicated how you do this.
class App(object):
def __init__(self, master):
self.master = master
self.frame = Frame(master)
self.frame.grid()
self.addFrame = Frame(master)
self.addFrame.grid(row=0, column=0, columnspan=2, sticky='N')
self.listFrame = Frame(master)
self.listFrame.grid(row=1, column=0, columnspan=2, sticky='NW')
self.todoList = []
self.initUI()
def initUI(self):
self.entryBox = Entry(self.frame, width = 15)
self.entryBox.grid(row=0, column=0, sticky='N')
self.addButton = Button(self.frame, text="<-ADD->", command=self.add)
self.addButton.grid(row=0, column=1, sticky='N')
def removeCheckButton(self):
# - CONFUSED HOW TO REMOVE THE SPECIFIC CHECKBUTTON
pass
def add(self):
entry = self.entryBox.get()
self.entryBox.delete(0, END)
self.todoList.append(entry)
print self.todoList
var1 = IntVar()
self.buttonList = []
for n in range(len(self.todoList)):
lx = Checkbutton(self.listFrame, text=self.todoList[n], variable=self.todoList[n], command=removeCheckButton)
lx.grid(row=n, column=0, sticky='NW')
self.buttonList.append(lx)
print self.buttonList
Have a look at this. your add is a bit strangely designed (and incorrectly IMO), so I modified it slightly as well as other parts.
from tkinter import *
class App(object):
def __init__(self, master):
self.master = master
self.frame = Frame(master)
self.frame.grid()
self.addFrame = Frame(master)
self.addFrame.grid(row=0, column=0, columnspan=2, sticky='N')
self.listFrame = Frame(master)
self.listFrame.grid(row=1, column=0, columnspan=2, sticky='NW')
self.todoList = []
self.buttonList = [] #<--- button list is here now
self.initUI()
def initUI(self):
self.entryBox = Entry(self.frame, width = 15)
self.entryBox.grid(row=0, column=0, sticky='N')
self.addButton = Button(self.frame, text="<-ADD->", command=self.add)
self.addButton.grid(row=0, column=1, sticky='N')
def removeCheckButton(self, button_no):
# - CONFUSED HOW TO REMOVE THE SPECIFIC CHECKBUTTON
# print(button_no, self.buttonList[button_no])
#self.buttonList[button_no].grid_forget()
self.buttonList[button_no].destroy()
# del self.buttonList[button_no]
# del self.todoList[button_no]
def add(self):
entry = self.entryBox.get()
self.entryBox.delete(0, END)
self.todoList.append(entry)
print(self.todoList)
var1 = IntVar()
#self.buttonList = [] #<--- not sense having this here
# for n in range(len(self.todoList)): #<-- this for also very strange here.
n = len(self.buttonList)
lx = Checkbutton(self.listFrame,
text=self.todoList[n],
variable=self.todoList[n],
command=lambda ni=n: self.removeCheckButton(ni))
lx.grid(row=n, column=0, sticky='NW')
self.buttonList.append(lx)
# print(self.buttonList)
root = Tk()
app = App(root)
root.mainloop()
P.S.
I use python 3, but except the import part, the code should execute for you. Probably it needs more fixing, but the checkboxes get destroyed now as they supposed to.

Categories

Resources