Python Forum
tkinter two windows instead of one
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter two windows instead of one
#6
You do this on line 172:
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-=1
You 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.
Reply


Messages In This Thread
RE: tkinter two windows instead of one - by deanhystad - Feb-05-2024, 09:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter multiple windows in the same window hosierycouch 1 131 May-30-2024, 04:28 AM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,829 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 1,033 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Dual Tkinter windows and shells Astrikor 6 4,158 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  Tkinter scaling windows conten to or with its size not working Detzi 5 4,631 Jan-12-2020, 12:42 PM
Last Post: Detzi
  How to close one of the windows in Tkinter scratchmyhead 3 4,924 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Using tkinter on Windows to launch python 3 scripts Mocap 1 2,825 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 2,794 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 4,264 May-26-2019, 10:24 AM
Last Post: Yoriz
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 4,554 Jul-23-2018, 02:41 PM
Last Post: Gangwick

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020