我喜欢GTK Headerbar。但是当我使用它时,我无法在一个过程中移动窗口。停止标题栏冻结窗口的好方法是什么?
此致
示例代码:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import time
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="HeaderBarTest")
self.connect("destroy", lambda w: Gtk.main_quit())
self.set_position(Gtk.WindowPosition.CENTER)
self.set_default_size(300, 300)
self.set_border_width(20)
# header bar
if True:
hb = Gtk.HeaderBar()
hb.set_show_close_button(True)
hb.props.title = "HeaderBarTest"
self.set_titlebar(hb)
self.box = Gtk.Box(spacing=6)
self.add(self.box)
self.button = Gtk.Button(label="Sleep")
self.box.pack_start(self.button, True, True, 0)
self.button.connect("clicked", self.sleep_function)
self.show_all()
Gtk.main()
def sleep_function(self, widget=None):
time.sleep(10)
if __name__ == "__main__":
app = MyWindow()
答案 0 :(得分:0)
一种解决方法是使用多处理:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import time
from multiprocessing import Process
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="HeaderBarTest")
self.connect("destroy", lambda w: Gtk.main_quit())
self.set_position(Gtk.WindowPosition.CENTER)
self.set_default_size(300, 300)
self.set_border_width(20)
# header bar
if True:
hb = Gtk.HeaderBar()
hb.set_show_close_button(True)
hb.props.title = "Convert2Html"
self.set_titlebar(hb)
self.box = Gtk.Box(spacing=6)
self.add(self.box)
self.button = Gtk.Button(label="Sleep")
self.box.pack_start(self.button, True, True, 0)
self.button.connect("clicked", self.on_sleep_button_clicked)
self.show_all()
Gtk.main()
def on_sleep_button_clicked(self, widget):
p = Process(target=self.sleep_function)
p.start()
def sleep_function(self, widget=None):
print "start"
time.sleep(6)
print "end"
if __name__ == "__main__":
app = MyWindow()