Search code examples
pythontkinterinterfacewindowtoplevel

Second Window is blank after a button was clicked in Main Window


I have two python file, the first one is contain the mainWindow, second python file contains another Window. I manage to make the second window appear but the window is blank after it appear. Here is the screen shot of the error. enter image description here

and here is what should show after the "Configuration" button clicks. enter image description here

In main window file, I define the code like this:

from tkinter import *
import configureUAHChange as cA

class TracingInterface(Frame):
    def __init__(self, master):
        super().__init__()
        root.minsize(width=700, height=520)
        root.maxsize(width=700, height=520)
        Frame.__init__(self, master)
        Grid.config(self)
        self.TracingMethod()
        self.logDetails()
        self.otherFunctionInterface()
        # Default window state
        self._configureUA_window = None

    def UAconfig_window(self):
        if self._configureUA_window is not None:
            return
        self._configureUA_window =cA.ConfigureUAinterface(self)

    def closeUA(self):
        # Destroy the 2nd and reset the value to None
        if self._configureUA_window is not None:
            self._configureUA_window.destroy()
            self._configureUA_window = None

This line is for the button click command:

self.configUAButton = Button(self.radioframe, text="Configuration",command=self.UAconfig_window)

Next, this is how I define the function in second python file

class ConfigureUAinterface(Toplevel):
def __init__(self, master):
    super().__init__(master)
    master.minsize(width=700, height=520)
    master.maxsize(width=700, height=520)

    Frame.__init__(self, master)
    Grid.config(self)

    master.title("UA Configuration")

    #Pre define combobox value in case suggestion
    self.value_of_combo='Identity Theft'

    #Run the all Function
    self.DateSelection()
    self.finish()
    self.UASuggestion()
    self.ConfigurationUA()
    self.suggestionCombo()

Please tell me how can modified my code to solve above error.

This is complete coding for main window :https://drive.google.com/open?id=1KKgYPbGMNNWBfPVazHfcM_NSFlv5eEpKg3_uXsvQsNE

This is complete coding for second window:https://drive.google.com/open?id=1LuqJXIUrDMLfuz8gnZynZXUN6-SvFAyw9c-puJ3REPQ


Solution

  • 1) I think there are some root that should be master in the __init__ function of TracingInterface.

    2) The master you pass to ConfigureUAinterface is not a window but a TracingInterface which is a frame and doesn't have minsize, maxsize and title methods.

    3) I don't know why you use Frame.__init__(self, master) while ConfigureUAinterface inherit from a Toplevel.

    Edit: Changes for the main window:

    class TracingInterface(Frame):
        def __init__(self, master):
            super().__init__()
    
            # 1) master instead of root (it was just a typo I think)
            master.minsize(width=700, height=520)
            master.maxsize(width=700, height=520)
            # Frame.__init__(self, master): redundant with super().__init__()
            Grid.config(self)
            self.TracingMethod()
            self.logDetails()
            self.otherFunctionInterface()
            # Default window state
            self._configureUA_window = None
    
        def UAconfig_window(self):
            if self._configureUA_window is not None:
                return None
            # 2) changed self which is a frame to the actual window self.master
            self._configureUA_window = cA.ConfigureUAinterface(self.master)
    

    Changes for the second window:

    class ConfigureUAinterface(Toplevel):
        def __init__(self, master):
            super().__init__(master)
            # replaced master by self since it's the Toplevel size we want to limit
            self.minsize(width=700, height=520)
            self.maxsize(width=700, height=520)
    
            # 3) The following is inapropriate since the widget 
            #    inherit from Toplevel, not Frame:
            #  Frame.__init__(self, master)
            #  Grid.config(self)
    
            # replaced master by self since it's the Toplevel title
            self.title("UA Configuration")
    
            #Pre define combobox value in case suggestion
            self.value_of_combo='Identity Theft'
    
            #Run the all Function
            self.DateSelection()
            self.finish()
            self.UASuggestion()
            self.ConfigurationUA()
            self.suggestionCombo()
    

    I didn't modify anything else in the code and when I tried, it worked.