Skip to content Skip to sidebar Skip to footer

Using The Variable From Entry/button In Another Function In Tkinter

When I press the button, I want it to get the Entry and -for future things- use it in another function. import tkinter def ButtonAction(): MyEntry = ent.get() #this is the var

Solution 1:

Structure the program using class.

import tkinter

classPrompt:
    defbutton_action(self):
        self.my_entry = self.ent.get() #this is the variable I wanna use in another functiondef__init__(self, den):
        self.lbl = tkinter.Label(den, text="Write Something")
        self.ent = tkinter.Entry(den)
        self.btn = tkinter.Button(den, text="Get That Something", command=self.button_action)
        self.lbl.pack()
        self.ent.pack()
        self.btn.pack()

den = tkinter.Tk()
den.title("Widget Example")
prompt = Prompt(den)
den.mainloop()

You can access the input using prompt.my_entry later.

Post a Comment for "Using The Variable From Entry/button In Another Function In Tkinter"