[split] New at Python programming - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [split] New at Python programming (/thread-6109.html) |
[split] New at Python programming - Akash - Nov-06-2017 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 RE: [split] New at Python programming - heiner55 - Nov-10-2017 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() |