Python Forum
Unable to return value from callback function of a button in Python Tkinter
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to return value from callback function of a button in Python Tkinter
#3
(Aug-05-2018, 12:58 PM)Windspar Wrote: 1. Don't flood namespace.
from Tkinter import *
this is better.
import Tkinter as tk
Example. Every thing seems to be working find.
import Tkinter as tk

class Menu:
    def __init__(self,master):
        self.master=master
        self.var1 = tk.StringVar()
        self.entry = tk.Entry(self.master, textvariable=self.var1)
        self.entry.pack(side=tk.TOP)

        self.button = tk.Button(self.master,text='Hit Me',command = self.get_value)
        self.button.pack(side=tk.TOP)
        self.value = None

    def get_value(self):
        print(self.entry.get())
        print(self.var1.get())
        self.value = self.entry.get()
        print(self.value)

if __name__=="__main__":
    root = tk.Tk()
    menu = Menu(root)
    root.mainloop()

Hi Windspar,
Thanks for your input.But what I want is to return the input value to a variable in the main program so that I can use t for other purpose. Actually my idea is to make one FTP GUI app so that user will provide input in GUI app & after the pressing Hit Me button the main program will be able to fetch the input details of user from this GUI. In this program if I am trying to return a value the output is coming as None. So, please tell me how I can use this input in entry box to another program? Again thank you very much for your input.
Reply


Messages In This Thread
RE: Unable to return value from callback function of a button in Python Tkinter - by nilaybnrj - Aug-05-2018, 05:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter callback exception Ben123 2 594 Feb-17-2024, 06:03 PM
Last Post: deanhystad
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,031 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 879 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 5,105 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,919 May-25-2023, 07:37 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,917 May-03-2022, 02:33 PM
Last Post: deanhystad
  Can't get tkinter button to change color based on changes in data dford 4 3,457 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] tkinter best way to pass parameters to a function Pedroski55 3 4,904 Nov-17-2021, 03:21 AM
Last Post: deanhystad
  Creating a function interrupt button tkinter AnotherSam 2 5,577 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,056 Oct-01-2021, 05:00 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020