Aswin Murugesh
Aswin Murugesh

Reputation: 11070

Disable input to a text box in GTk python

I was developing a simple calculator in python using Gtk. In that calculator, if an expression such as 4*3 is entered and = is pressed, the result is displayed. But after that, if any other button is pressed, the number is appended on the screen (ie) if i press 4*3 = it shows 12, after which i press 3 and i get 123. I used

tb.set_editable(False)

but it stopped only the keyboard inputs, and the problem persists when i press any button. I want to change it such a way that if a new entry is pressed,the screen should clear...

Please help me on what i can do....

Upvotes: 1

Views: 1146

Answers (1)

Yoriz
Yoriz

Reputation: 3625

Have a variable that is initially set as False, say we call it say calculated.

In your key press event callback:

  • If the key press is '=' append the calculated value and set calculated to True.

  • If calculated is True and the key press is not '=' clear the value before setting it and set calculated to False.

Upvotes: 2

Related Questions