Feb-05-2024, 09:13 PM
(This post was last modified: Feb-07-2024, 12:14 PM by deanhystad.)
You do this on line 172:
And I don't see where you ever use the correct arguments for making buttons or labels. Instead of this:
The first argument should always be the parent window for the widget. If you leave this out, the default is to add widgets to the window created by Tk(). This lazy behavior will start causing more problems as your windows become more complicated.
Additional comments.
Learn about list pack/unpack. Instead of this:
As mentioned in your other thread, this will not work:
if __name__ == "__main__": window = Tk()And this on line 41
def setup_gui(self): # make a list of the 4 past and 4 upcoming days for index, dat in enumerate(self.dates_list): if dat == datetime.today().strftime('%a %d %B %Y'): self.updated_list.extend(self.dates_list[index - 5:index+6]) self.window = Tk()That is 2 windows. Calling Tk() twice in a program is also an error.
And I don't see where you ever use the correct arguments for making buttons or labels. Instead of this:
gen_row_but = Button(text="Add entry", command=self.add_column)You really need to do this:
gen_row_but = Button(window, text="Add entry", command=self.add_column)You only specify the parent window when you make option menus. That is why option menus show in the other window.
The first argument should always be the parent window for the widget. If you leave this out, the default is to add widgets to the window created by Tk(). This lazy behavior will start causing more problems as your windows become more complicated.
Additional comments.
Learn about list pack/unpack. Instead of this:
self.day_opt.append(OptionMenu(self.window,self.day_value_inside, self.updated_list[0], self.updated_list[1], self.updated_list[2], self.updated_list[3], self.updated_list[4], self.updated_list[5], self.updated_list[6], self.updated_list[7], self.updated_list[8], self.updated_list[9]))do this:
self.day_opt.append(OptionMenu(self.window, self.day_value_inside, *self.updated_list))This is an error
self.act_opt.append(OptionMenu(self.window,self.act_value_inside,"Aerobics", "Cycling","Running", "Swimming", "Walking"))You cannot reuse the self.act_value_inside. You need to create a new variable for each OptionMenu instance.
As mentioned in your other thread, this will not work:
def remove_button(self): self.day_lbl[-1].forget() self.act_lbl[-1].forget() self.day_opt[-1].forget() self.act_opt[-1].forget() self.unit_lbl[-1].forget() self.unit_ent[-1].forget() self.min_lbl[-1].forget() self.count-=1You are using the wrong type of forget (need to use grid_forget()), and your logic is wrong. Your forgotten widgets remain in the lists. When you call remove_button() a second time it forgets the already forgotten widgets.