pygtk关闭button控件
时间:2011-07-26
来源:互联网
我在学习python gtk,
Python code
上面的例子运行后,点击button1,会出现,Hello again - button 1 was pressed
可否更改这个程序,使他在点击button1后,button1这个控件消失?
Python code
#!/usr/bin/env python # example helloworld2.py import pygtk pygtk.require('2.0') import gtk class HelloWorld2: # Our new improved callback. The data passed to this method # is printed to stdout. def callback(self, widget, data): print "Hello again - %s was pressed" % data # another callback def delete_event(self, widget, event, data=None): gtk.main_quit() return False def __init__(self): # Create a new window self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) # This is a new call, which just sets the title of our # new window to "Hello Buttons!" self.window.set_title("Hello Buttons!") # Here we just set a handler for delete_event that immediately # exits GTK. self.window.connect("delete_event", self.delete_event) # Sets the border width of the window. self.window.set_border_width(10) # We create a box to pack widgets into. This is described in detail # in the "packing" section. The box is not really visible, it # is just used as a tool to arrange widgets. self.box1 = gtk.HBox(False, 0) # Put the box into the main window. self.window.add(self.box1) # Creates a new button with the label "Button 1". self.button1 = gtk.Button("Button 1") # Now when the button is clicked, we call the "callback" method # with a pointer to "button 1" as its argument self.button1.connect("clicked", self.callback, "button 1") # Instead of add(), we pack this button into the invisible # box, which has been packed into the window. self.box1.pack_start(self.button1, True, True, 0) # Always remember this step, this tells GTK that our preparation for # this button is complete, and it can now be displayed. self.button1.show() # Do these same steps again to create a second button self.button2 = gtk.Button("Button 2") # Call the same callback method with a different argument, # passing a pointer to "button 2" instead. self.button2.connect("clicked", self.callback, "button 2") self.box1.pack_start(self.button2, True, True, 0) # The order in which we show the buttons is not really important, but I # recommend showing the window last, so it all pops up at once. self.button2.show() self.box1.show() self.window.show() def main(): gtk.main() if __name__ == "__main__": hello = HelloWorld2() main()
上面的例子运行后,点击button1,会出现,Hello again - button 1 was pressed
可否更改这个程序,使他在点击button1后,button1这个控件消失?
作者: fnzh0003 发布时间: 2011-07-26
不要show button不就行了。。。
作者: BoredNight 发布时间: 2011-07-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28