Python Forum
[split] New at Python programming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] New at Python programming
#1
from tkinter import *
import random
import time

class val:
def __init__(self):
self.values=
self.index=0
def assign(self):
self.values.append(random.randint(0,9))
def callback(self):
v.set(self.values[self.index])
time.sleep(0.5)
self.index+=1

root=Tk()
v=StringVar()

L1=Label(root,text="Number").grid(row=1,column=1)
E1=Entry(root,textvariable=v,bd=5).grid(row=1,column=2)

obj=val()
root.mainloop()


This is my code above. I am using Python 3.6 version. I want to make a entry widget which should set a value randomly by getting data from random variable. But I am not getting any value in the entry widget while i run this program. please give me solution
Reply
#2
Maybe this helps:

from tkinter import *
import random
import time

class Val:
  def __init__(self):
    pass
  def callback(self):
    E1.delete(0, END)
    E1.insert(0, random.randint(0,999))

root=Tk()
obj=Val()

L1 = Label(root,text="Number")
E1 = Entry(root)
B1 = Button(root,text="Click",command=obj.callback)

L1.grid(row=1,column=1)
E1.grid(row=1,column=2)
B1.grid(row=1,column=3)

root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Start learning GUI Programming python sumandas89 1 1,878 Jan-18-2019, 02:11 PM
Last Post: Larz60+
  New at Python programming rsmldmv 1 1,860 Nov-03-2017, 02:48 AM
Last Post: Larz60+
  [PyGUI] Opinions on Python GUI programming cdn 2 3,394 Aug-26-2017, 11:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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