0

Hi guys I'm using page to create the gui for my project;but when I try to use the button to open the window two from window 1 giving it as a parameter main or rot in it , it is not displayed giving as error main not definied

In a separate python file I have the graphical interface, in another python file I have a graphic interface that has to open the other interface present in the first file through the button, I imported the functions of the first file in the second one and reads the creation functions; but when I have to use the function create_toplevel1 giving it as a parameter the main on which the first window exits, it tells me that it is not defined, the same thing for root, and without parameters it is not possible because the function necessarily accepts a parameter

#first main when I click the button and appear the second window

class AdminPanel:
   def __init__(self, top=None):
       '''This class configures and populates the toplevel window.
          top is the toplevel containing window.'''
       self.btnregutenti =tk.Button(top,command=create_TopLevel1(root))

def create_AdminPanel(root, *args, **kwargs):
   '''Starting point when module is imported by another program.'''
   global w, w_win, rt
   rt = root
   w = tk.Toplevel (root)
   top = AdminPanel (w)
   return (w, top)


#second window that appear when I use a button

def create_TopLevel1(root, *args, **kwargs):
   '''Starting point when module is imported by another program.'''
   global w, w_win, rt
   rt = root
   w = tk.Toplevel (root)
   top = TopLevel1 (w)
  # user_interface_support.init(w, top, *args, **kwargs)
   return (w, top)

in this instruction self.btnregutenti=tk.Button(top,command=create_TopLevel1(root))

what parameter I should insert to show the correct window?

vin0zero
  • 3
  • 5
  • 3
    ***`,command=create_TopLevel1(root)`***: Read [Why is Button parameter “command” executed when declared?](https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared) – stovfl Oct 22 '19 at 09:48

1 Answers1

0

The problem is that the Button takes a function as a command= argument value. By using tk.Button(top,command=create_TopLevel1(root)) you're already calling the function. You should instead use tk.Button(top,command=create_TopLevel1) and edit create_TopLevel1 so it doesn't require any arguments. Hope that's helpful!

rizerphe
  • 1,340
  • 1
  • 14
  • 24