Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic button text
#1
hi I am putting some code together that uses a pickle file that saves my data from previous session. I have a set up page that allows the users to change the text on the buttons but I am having way to much trouble trying to get the buttons to update using a textvariable and been on the google all day almost

Hope some one can point me in the right direction please.

self.MyList = loaddata()
        print(self.MyList)

        self.text1=((self.MyList[4]))
        print(self.text1)


   



        self.button1 = tk.Button(self.frame, textvariable  = self.text1, width = 25, command=self.capture_asset)
        self.button1.grid(row=2, column=3) 
Mylist comes from the pickle file when I print self.text1 is fine and shows the text string I want to put on the button but the button shows a blank text?
Reply
#2
If I remember well, the textvariable parameter in tkinter widgets needs a tkinter StringVar value. It should probably be

self.text1 = tk.StringVar()
self.text1.set(self.Mylist[4])
...
Reply
#3
Thanks for the suggestion but I tried that one and it doesn't look to like StringVar saying unresolved reference and error is stringvar not defined?
Reply
#4
StringVar is in tkinter. If you import tkinter as tk you need a qualified name tk.StringVar()
Reply
#5
Brillant well done that man!! Wondered why it never showed up as I was typing it now I know.

Thanks a mill
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Start print a text after open an async task via button Nietzsche 0 671 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Change the text in the button object chris0147 1 2,859 Sep-02-2017, 04:40 AM
Last Post: kalyanben

Forum Jump:

User Panel Messages

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