loops - Python - Continous Button Inputing (Sort of like BCD) -


i trying make simlar calculator, not full fledge one, 1 take inputs buttons , make operations on them. trying figure out how can user ınput using buttons. know how ms calculator works, eh? (or other calculator basically, or keyboard itself). shifts input give , writes down. ı asking this: user presses "1" "5" "3". want variable in program stored "153".

sorry bad explaination, have no idea how can express problem properly.

i dont have code built yet. contains tk window, buttons, , functions.

thanks :) !

edit: current code has: imports tkinter, creates: (master=tk()) creates 10 buttons labeled 0-9. , pretty it.

buttons labeled b0, b1, b2 ...

i have tried appending them in list, somehow combining elements of list 1 integer. couldnt figure out.

well, easier if post gui code you've created, in general, 1 way store string representing current number being entered. if user presses numerical button, new digit appended end of current number. example,

for example:

class calculator:     def __init__(self):         # ... you'd set rest of gui ..         self.buttons = {}  # store calculator buttons in dictioanry         num in [str(x) x in range(10)]:             self.buttons[num] = tkinter.button(self.keyframe, text=num, command=self.callbackcreator(num))         self.currentnumber = ""      def callbackcreator(self, num):         return lambda event:self.buttoncallback(num)      def buttoncallback(key):         if key in "0123456789":        # check if button digit or not             self.currentnumber += key  # add new digit 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -