0

I have created several individuall windows with tkinter and now I want to connect them. So implementing several "Forward" and "Back" Buttons. This should be simple but it turns out to screw with me alot.

This can be seen as a practical application issue of this question: Go back and forth between tkinter windows

I implemented the explained logic the best I can but still fail.

My specific Issues are:

  • When I klick the "Reports"-button the new window opens but: the original window(cockpit) doesnt disapear and a second window opens which is just the Original Cockpit window but without any widgets in it (just the frame?)

  • Also when I hit the "Back" Button this error Message Appears: self.ReportSelection_Win.withdraw() AttributeError: 'Event' object has no attribute 'ReportSelection_Win'

I stripped the following code of most of its functions since they arent neccessary for the issue I think. So most button dont have any function.

from tkinter import * 
from tkinter import ttk  


#Funktionen für Fenster    
def Func_Show_Rep(self):    
    # Open new Window
    ReportSelection_Win = Tk()
    self.ReportSelection_Win = Toplevel()  

    ReportSelection_Win.title("Report auswählen")

    #Dropdown Auswahlliste
    Reports = [
    "Alle Mitarbeiter",
    "Alle Projekte",
    "Alle Skills"
    ]

    #Widgets
    #Labels & Dropdown
    Lbl_Headline = Label(ReportSelection_Win, text = "Bitte wählen Sie einen Report")#Create Label
    Lbl_Headline.grid(column=0, row=0, padx=10, pady=10) #Show Label

    Drop_Reports = ttk.Combobox(ReportSelection_Win)
    Drop_Reports.grid(column=0, row=1, padx=10, pady=10)
    Drop_Reports['values'] = Reports

    #Buttons
    Btt_Confirm_RepSelect = Button(ReportSelection_Win, text="Auswählen")
    Btt_Confirm_RepSelect.bind("<Button-1>", Select_Report)
    Btt_Confirm_RepSelect.grid(column=0, row=2, padx=10, pady=10, sticky=W)

    Btt_Back_RepSelect = Button(ReportSelection_Win, text="Zurück")
    Btt_Back_RepSelect.bind("<Button-1>", Func_ReportSelection_Back)#Back to Cockpit
    Btt_Back_RepSelect.grid(column=0, row=2, padx=10, pady=10, sticky=E)

    self.Cockpit_Win.withdraw() #.deiconify() to show again

#Funktionen für Report Fenster    
def Func_ReportSelection_Back(self):
    self.ReportSelection_Win.withdraw()
    self.Cockpit_Win.deiconify()



#Modify the Window [◙Not essential for Issue]
Cockpit_Win.title("Ressourcen Verwaltung")
Cockpit_Win.columnconfigure(1, weight=1)

Lbl_Descr_MA = Label(Cockpit_Win, text = "Mitarbeiter verwalten und anlegen")#Create Label
Lbl_Descr_MA.grid(column=0, row=0, padx=10) #Show Label

Btt_Show_MA = Button(Cockpit_Win, text="Mitarbeiter", width=35)
Btt_Show_MA.bind("<Button-1>",Func_Show_MA)#Button click starts function
Btt_Show_MA.grid(column=1, row=0, padx=10, pady=7, sticky=E)

Lbl_Descr_Pro = Label(Cockpit_Win, text = "Projekte Verwalten und anlegen.")#Create Label
Lbl_Descr_Pro.grid(column=0, row=1, padx=10) #Show Label

Btt_Show_Pro = Button(Cockpit_Win, text="Projekte", width=35)
Btt_Show_Pro.bind("<Button-1>",Func_Show_Pro)#Button click starts function
Btt_Show_Pro.grid(column=1, row=1, padx=10, pady=7, sticky=E)

Lbl_Descr_Rep = Label(Cockpit_Win, text = "Report auswählen und ausgeben")#Create Label
Lbl_Descr_Rep.grid(column=0, row=2, padx=10) #Show Label

Btt_Show_Rep = Button(Cockpit_Win, text="Reports", width=35)
Btt_Show_Rep.bind("<Button-1>",Func_Show_Rep)#Button click starts function
Btt_Show_Rep.grid(column=1, row=2, padx=10, pady=7, sticky=E)

Btt_Cock_Abort = Button(Cockpit_Win, text="Abbrechen", width=35)
Btt_Cock_Abort.bind("<Button-1>",Func_Cock_Abort)#Button click starts function
Btt_Cock_Abort.grid(column=1, row=3, padx=10, pady=7, sticky=E)

Cockpit_Win.geometry('350x170') #Window size


#Make the windows stay (loop)      
Cockpit_Win.mainloop()
G.M
  • 345
  • 3
  • 22
  • What's the difference between this question and the other one u asked? – Henry Yik Aug 30 '19 at 11:33
  • The other question was about how it generally works and a little bit of theory. But it isnt tied to any specifc application. Now after trying to apply the learned stuff I ran into specific errors which i hope to fix. I see your issue since both questions are related. Thats why linked the original. I decided to create a new questions since the answer for both questions will be quiet different and mostly independent from each other (even though the questions are related) --> the Issue should be with the code _around_ `.withdraw()` and the .deiconify()` not these functions themself I hope :) – G.M Aug 30 '19 at 11:51
  • 1
    Next time you post question like that reduce code to minimum working example – Robot Mind Aug 30 '19 at 13:05

1 Answers1

1

I reduced your code to almost minimal working case.

from tkinter import * 
from tkinter import ttk  


#Funktionen für Fenster   
def Func_Show_Rep(even = None):
    global Cockpit_Win
    Cockpit_Win.withdraw()#.deiconify() to show again
    ReportSelection_Win = Toplevel() 
    Show_Rep(ReportSelection_Win, Cockpit_Win)

class Show_Rep():    
    # Hide old Window

    def __init__(self, master, Cockpit_Win):
        # Open new Window

        self.ReportSelection_Win =master 
        self.ReportSelection_Win.title("Report auswählen")

        #Dropdown Auswahlliste
        Reports = [
        "Alle Mitarbeiter",
        "Alle Projekte",
        "Alle Skills"
        ]

        #Widgets
        #Labels & Dropdown
        Lbl_Headline = Label(self.ReportSelection_Win, text = "Bitte wählen Sie einen Report")#Create Label
        Lbl_Headline.grid(column=0, row=0, padx=10, pady=10) #Show Label

        Drop_Reports = ttk.Combobox(self.ReportSelection_Win)
        Drop_Reports.grid(column=0, row=1, padx=10, pady=10)
        Drop_Reports['values'] = Reports

        #Buttons

        Btt_Back_RepSelect = Button(self.ReportSelection_Win, text="Zurück")
        Btt_Back_RepSelect.bind("<Button-1>", self.Func_ReportSelection_Back)#Back to Cockpit
        Btt_Back_RepSelect.grid(column=0, row=2, padx=10, pady=10, sticky=E)

    #Funktionen für Report Fenster    
    def Func_ReportSelection_Back(self, event = None):
        self.ReportSelection_Win.withdraw()
        Cockpit_Win.deiconify()


Cockpit_Win = Tk()
#Modify the Window [◙Not essential for Issue]
Cockpit_Win.title("Ressourcen Verwaltung")
Cockpit_Win.columnconfigure(1, weight=1)



Lbl_Descr_Rep = Label(Cockpit_Win, text = "Report auswählen und ausgeben")#Create Label
Lbl_Descr_Rep.grid(column=0, row=2, padx=10) #Show Label

Btt_Show_Rep = Button(Cockpit_Win, text="Reports", width=35)
Btt_Show_Rep.bind("<Button-1>",Func_Show_Rep)#Button click starts function
Btt_Show_Rep.grid(column=1, row=2, padx=10, pady=7, sticky=E)



Cockpit_Win.geometry('350x170') #Window size


#Make the windows stay (loop)      
Cockpit_Win.mainloop()

Explanation: I crated class that writes your reports to window. And function that hides your main_window, makes Topwindow

Robot Mind
  • 321
  • 1
  • 6