这是我的问题的一个小实现。当我单击“按下”按钮时,它会挂起,有时不会。如何克服这个问题?这是我的代码。
安装 Sane “sudo apt-get install python-imaging-sane”
import gtk
import gtk.glade
import threading
import os
import sane
gtk.gdk.threads_init()
class process(threading.Thread):
def __init__(self,main_object):
self.main_object = main_object
threading.Thread.__init__(self)
def run(self):
sane_version = sane.init()
sane_devices = sane.get_devices()
gtk.threads_enter()
self.main_object.pb.set_fraction(self.main_object.value)
gtk.threads_leave()
self.main_object.value = self.main_object.value + .1
class main():
def __init__(self):
#GUI
window = gtk.Window()
window.set_default_size(200,200)
vbox = gtk.VBox(False,0)
self.pb = gtk.ProgressBar()
button = gtk.Button("Press me ")
button.connect("clicked",self.fun_to_call)
vbox.pack_end(self.pb)
vbox.pack_end(button)
button.show()
self.pb.show()
vbox.show()
window.add(vbox)
self.value = .1
window.show()
def fun_to_call(self,data=None):
pro = process(self)
pro.start()
main()
gtk.main()