0

I am creating a python application. whenever I print the argument (the content of the entry widget) I get nothing instead of what I entered. here is my code:

class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.withdraw()
        self.root1 = Tk()  
        self.root1.geometry('800x690')  
        self.root1.title('1')

        self.root2 = Tk()  
        self.root2.geometry('800x690')  
        self.root2.title('2')
        self.root2.withdraw()

        usernameLabel3 = Label(self.root2, text="Asset category",font=("Arial", 10),height= 1, 
        width=15)
        self.u3 = StringVar(None)
        usrIn3 = Entry(self.root2, textvariable = self.u3, width = 30)
        bt = ttk.Button(self.root2 , text = 'func', command = partial(func,self.u3))
    def func(self,u3):
        print(u3.get())

when I write the func before the App class the result was same.How can I get the argument I entered?

Bar oo.
  • 11
  • 3
  • 1
    `partial(func,self.u3)` should have generated an error, because the name `func` is not in scope at that point. I suspect that you have another definition of `func` in your actual code, that does something different from the intended `.func()` method. Use `self.func` instead. – jasonharper Jul 14 '23 at 14:35
  • 1
    Oh, I didn't even notice a more fundamental problem with your code - you're calling `Tk()` more than once, each of which has its own entirely independent set of Vars and other objects. If the Var and widget belong to different `Tk` instances, there is no actual connection between them. Use `Toplevel()` instead to create additional windows, that share the existing `Tk` instance so no such problems occur. – jasonharper Jul 14 '23 at 14:42
  • I changed the tk() to Toplevel() and the problem was solved. Thank you very much – Bar oo. Jul 14 '23 at 14:56

0 Answers0