update a gtk.VBox dynamically(动态更新 gtk.VBox)
问题描述
我经常使用这个网站来解决我在使用 Python 编程时遇到的小问题.这一次,不知何故我找不到适合我情况的解决方案.所以,这是我的问题:
I have been using this website pretty often in order to solve small issues that I have while programming in Python. This time, somehow I could not find a suitable solution for my situation. So, here is my problem:
我想动态地将条目添加到 gtk.VBox 小部件.问题是它不能按照我想要的方式工作.我只有一个按钮,它的作用是向 VBox 添加一个额外的小部件.不幸的是,小部件没有出现在窗口上.我想,我必须添加类似 repaint 函数调用的东西,但我没有找到类似的东西.这是一个示例代码,显示了我的问题:
I want to dynamically add entries to a gtk.VBox widget. The problem is that it doesn't work the way I want it to work. I simply have a button, whose action is to add an additional widget to a VBox. Unfortunately the widget doesn't appear on the window. I guess, I have to add something like a repaint function call, but I didn't find anything like that. Here is a sample code, showing my problem:
import gtk
class DynamicVbox:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.close_application)
self.window.set_size_request(400,320)
#a hBox to put the button and the dynamic vBox
hBox = gtk.HBox(False, 0)
addButton = gtk.Button("add checkbox")
addButton.connect("clicked", self.AddCheckButton)
self.vBox = gtk.VBox(False, 0)
self.vBox.pack_start(gtk.CheckButton("CheckButton"), True, True, 1)
hBox.pack_start(self.vBox, True, True, 5)
hBox.pack_end(addButton, False, False, 5)
self.window.add(hBox)
#start gtk
self.window.show_all()
gtk.main()
def AddCheckButton(self, button):
self.vBox.pack_start(gtk.CheckButton("CheckButton"), True, True, 1)
print "adding checkbox..."
def close_application(self, widget):
gtk.main_quit()
# run it
a = DynamicVbox()
感谢任何帮助.提前致谢.
A appreciate any help. Thanks in advance.
推荐答案
新的检查按钮在那里,但在你调用 show()
之前是不可见的:
The new check button is there, but not visible until you call show()
on it:
def AddCheckButton(self, button):
button = gtk.CheckButton("CheckButton")
self.vBox.pack_start(button, True, True, 1)
button.show()
print "adding checkbox..."
这篇关于动态更新 gtk.VBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态更新 gtk.VBox
基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01