检查按钮是否被点击
Checking if a Button was clicked
如何检查按钮是否被单击?这段代码可以工作还是我必须使用不同的 command/syntax?
def div_clicked(self, button14):
self.entry.set_text(self.entry.get_text() + str("/"))
if button14 == "clicked":
self.equal_clicked()
self.arithmetic = "division"
尤其是这一行:
if button14 == "clicked":
我想知道如何更改代码以便调用 self.equal_clicked()
函数。
由于您的问题被标记为 pygtk,我假设您使用的是 GTK 2。在这种情况下,请查看 http://www.pygtk.org/pygtk2tutorial/ch-GettingStarted.html#sec-HelloWorld。
这将为您提供一个关于如何处理按钮点击和其他事件的良好起点。我在下面粘贴了一个稍微剥离的版本:
import pygtk
pygtk.require('2.0')
import gtk
class HelloWorld:
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
def hello(self, widget, data=None):
print "Hello World"
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
# Creates a new button with the label "Hello World".
self.button = gtk.Button("Hello World")
# When the button receives the "clicked" signal, it will call the
# function hello() passing it None as its argument. The hello()
# function is defined above.
self.button.connect("clicked", self.hello, None)
self.window.add(self.button)
self.button.show()
self.window.show()
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()
扩展你的代码,你可以把这个表格做成
self.button14.connect("clicked", self.button14_click, "division")
def button14_click(self, button, data):
self.entry.set_text(self.entry.get_text() + str("/"))
self.equal_clicked()
self.arithmetic = data
如何检查按钮是否被单击?这段代码可以工作还是我必须使用不同的 command/syntax?
def div_clicked(self, button14):
self.entry.set_text(self.entry.get_text() + str("/"))
if button14 == "clicked":
self.equal_clicked()
self.arithmetic = "division"
尤其是这一行:
if button14 == "clicked":
我想知道如何更改代码以便调用 self.equal_clicked()
函数。
由于您的问题被标记为 pygtk,我假设您使用的是 GTK 2。在这种情况下,请查看 http://www.pygtk.org/pygtk2tutorial/ch-GettingStarted.html#sec-HelloWorld。
这将为您提供一个关于如何处理按钮点击和其他事件的良好起点。我在下面粘贴了一个稍微剥离的版本:
import pygtk
pygtk.require('2.0')
import gtk
class HelloWorld:
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
def hello(self, widget, data=None):
print "Hello World"
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
# Creates a new button with the label "Hello World".
self.button = gtk.Button("Hello World")
# When the button receives the "clicked" signal, it will call the
# function hello() passing it None as its argument. The hello()
# function is defined above.
self.button.connect("clicked", self.hello, None)
self.window.add(self.button)
self.button.show()
self.window.show()
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()
扩展你的代码,你可以把这个表格做成
self.button14.connect("clicked", self.button14_click, "division")
def button14_click(self, button, data):
self.entry.set_text(self.entry.get_text() + str("/"))
self.equal_clicked()
self.arithmetic = data