Capturing input using tkinter in Python 3.2 -
our inventory system generates 10 digit item numbers based on pattern. have written program following:
- take 10 digit item number incorrect digit , return list of possible valid item numbers changing each of digits.
- take 9 digit item number missing digit , return list of valid 10 digit item numbers inserting digit
- take 11 digit item number has digit , return list of valid 10 digit item numbers removing digit
- take 10 digit item number 2 digits transposed , return list of valid 10 digit item numbers switching digits
i have 5 functions accomplish task. function each of above instances , function determines if item number valid or not. working correctly.
now start program gui presents above 4 options along quit option. menu of sorts listing 1-5 user choose. once user inputs option number want 1 thru 5, need user prompted input item number have return list of possible item numbers printed out in gui.
i use tkinter create gui if possible 1 have limited knowledge of. using python 3.2.2. possible?
update::
after looking @ suggestions have following code:
class app: def __init__(self, master): frame = frame(master) frame.pack() self.l=label(frame, width = 50, anchor=center, justify=center, text="please choose following options: \n1. option1\n2. option2\n3. option3\n4. option4\n5. quit") self.l.pack() self.e = entry(frame, width=5) self.e.pack() self.e.focus_set() self.w1=label(frame, text="please enter 1-5") self.w1.pack() self.e1=entry(frame, width=16) self.e1.pack() self.e1.focus_set() self.w2=label(frame, text="enter item number") self.w2.pack() self.button=button(frame, text="return list", state=disabled) self.button.pack() root = tk() app=app(root) root.mainloop() now question how take information 2 entry widgets(self.e , self.e1) , use button execute function.
for example, if user enters option 4 on self.e entry widget , 1234567890 on self.e1 widget , presses button need call function option4(1234567890).
i need both entry widgets return numbers seem stuck how accomplish that. realize in button widget need replace state= command= not sure how bind e.get() , e2.get() button.
thanks help!
that has many different solution, bu anyway have create tkinter variable , connect self.e entry. that:
import tkinter tk ...then code class declaration , on... self.var1 = tk.stringvar() self.e = tk.entry(frame, textvariable = self.var1) by declaration you'll type e entry, put var1 variable. able acces value of var1 self.var1.get()
and couple function func(*args) button following way:
self.btn = tk.button(frame, text = 'some text', command = func) note func, not func(*args). tk.button command option should handler of function.
also, try http://www.tkdocs.com/tutorial/ whch point sart uderstanding how guis tk, in opinion
Comments
Post a Comment