如何在Ubuntu中的PyGTK或GTK中打开列表窗口? [英] How to get list opened windows in PyGTK or GTK in Ubuntu?
问题描述
如何在PyGTK或GTK或其他编程语言中打开列表窗口?在Ubuntu中?
编辑:
桌面!
您可能想要使用libwnck:
< a href =http://library.gnome.org/devel/libwnck/stable/ =noreferrer> http://library.gnome.org/devel/libwnck/stable/
我相信在python-gnome或类似的包中有python绑定。
一旦你运行了GTK +主循环,您可以执行以下操作:
导入wnck
window_list = wnck.screen_get_default()。get_windows()
一个窗口中有趣的方法是get_name()和activate()。
这将在您点击按钮时将窗口的名称打印到控制台。但由于某种原因,我不得不单击按钮两次。这是我第一次使用libwnck,所以我可能错过了一些东西。 : - )
导入pygtk
pygtk.require('2.0')
导入gtk,wnck
class WindowLister:
def on_btn_click(self,widget,data = None):
window_list = wnck.screen_get_default()。get_windows()
if len(window_list)== 0:
printNo Windows Found
赢得window_list:
print win.get_name()
$ b $ def __init __(self):
self .window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.button = gtk.Button(List Windows)
self.button.connect(clicked,self.on_btn_click,无)
self.window.add(self.button)
self.window.show_all()
def main(self):
gtk .main()
if __name__ ==__main__:
lister = WindowLister()
lister.main()
How to get list opened windows in PyGTK or GTK or other programming language? in Ubuntu?
edit:
i want get list paths opened directories on desktop!
You probably want to use libwnck:
http://library.gnome.org/devel/libwnck/stable/
I believe there are python bindings in python-gnome or some similar package.
Once you have the GTK+ mainloop running, you can do the following:
import wnck window_list = wnck.screen_get_default().get_windows()
Some interesting methods on a window from that list are get_name() and activate().
This will print the names of windows to the console when you click the button. But for some reason I had to click the button twice. This is my first time using libwnck so I'm probably missing something. :-)
import pygtk pygtk.require('2.0') import gtk, wnck class WindowLister: def on_btn_click(self, widget, data=None): window_list = wnck.screen_get_default().get_windows() if len(window_list) == 0: print "No Windows Found" for win in window_list: print win.get_name() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.button = gtk.Button("List Windows") self.button.connect("clicked", self.on_btn_click, None) self.window.add(self.button) self.window.show_all() def main(self): gtk.main() if __name__ == "__main__": lister = WindowLister() lister.main()
这篇关于如何在Ubuntu中的PyGTK或GTK中打开列表窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!