Python Forum
[Tkinter] Update value in Entry widget
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Update value in Entry widget
#2
it doesnt look like the problem is with GUI, it looks like your problem is with your programming. 

Quote:
def start():
    for n in range(1000000):
        if n%100000 == 0:
            v.set(str(n))

Every time you hit the button you execute start(). This function sets the string var (v) to every 100K (0-900000) in a split second. The last value 900000 gets seen as the label because its the last iteration and the completion of the function. Thus you will not see any other number in the label like you would with the print function...assuming this is what you wanted to do?

EDIT:
Do you mean something like this? I would suggest to use classes instead of global keywords. 
from tkinter import *

class Values:
    def __init__(self):
        self.vals = []
        self.index = 0
        self.assign()
    def assign(self):
        '''get our values'''
        for n in range(1000000):
            if n%100000 == 0:
                self.vals.append(n)
    def reset(self):
        '''what do we do when we iterate all values? Start at 0'''
        if self.index > len(self.vals)-1: 
            self.index = 0
            
    def callback(self):
        '''execute when button gets pressed'''
        self.reset()
        v.set(self.vals[self.index])
        self.index += 1
        

win = Tk()
v = StringVar()
obj = Values()
frame1 = Frame(win)
frame1.pack()
Label(frame1, text="Number").grid(row=0, column=0, sticky=W)

m = Label(frame1, textvariable=v)
m.grid(row=0, column=1, sticky=W)
frame2 = Frame(win)
frame2.pack()
b1 = Button(frame2,text=" Start  ",command=obj.callback)
b1.pack(side=LEFT)
#win = makeWindow()
win.mainloop()
Recommended Tutorials:
Reply


Messages In This Thread
Update value in Entry widget - by dannyH - Mar-25-2017, 11:18 PM
RE: Update value in Entry widget - by metulburr - Mar-26-2017, 12:13 AM
RE: Update value in Entry widget - by dannyH - Mar-26-2017, 07:05 AM
RE: Update value in Entry widget - by Barrowman - Mar-31-2017, 04:38 PM
RE: Update value in Entry widget - by metulburr - Mar-31-2017, 05:22 PM
RE: Update value in Entry widget - by dannyH - Mar-31-2017, 09:54 PM
RE: Update value in Entry widget - by wuf - Apr-01-2017, 06:03 PM
RE: Update value in Entry widget - by dannyH - Apr-02-2017, 10:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 1,327 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,847 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  How to instantly update the plot by getting values from a Scale widget? OLE 20 7,076 May-18-2022, 02:35 AM
Last Post: OLE
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,381 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  [Tkinter] Update variable using tkinter entry methon drSlump 6 5,608 Oct-15-2021, 08:01 AM
Last Post: drSlump
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,455 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  Entry Widget issue PA3040 16 7,411 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,589 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,746 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to retreive the grid location of an Entry widget kenwatts275 7 5,047 Apr-24-2020, 11:39 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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