我正在尝试制作一个程序(在python中),当我将它写入文件并打开到我已经创建的某个窗口时。我已经为一个可行的解决方案寻找了allarund bt似乎多线程可能是唯一的选择。
I was hoping that when option autorun is "activated" it will:
while 1:
wbuffer = textview.get_buffer()
text = wbuffer.get_text(wbuffer.get_start_iter(), wbuffer.get_end_iter())
openfile = open(filename,"w")
openfile.write(text)
openfile.close()
我正在使用 pygtk 并且有一个 textview 窗口,但是当我得到缓冲区时,它会永远存在。我在想我需要多线程并对其进行排队,以便一个线程在排队时写入缓冲区。
我的来源在这里。(我认为声明在第 177 行。)
任何帮助深表感谢。:)
这是功能:
def autorun(save):
filename = None
chooser = gtk.FileChooserDialog("Save File...", None,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
response = chooser.run()
if response == gtk.RESPONSE_OK: filename = chooser.get_filename()
filen = filename
addr = (filename)
addressbar.set_text("file://" + filename)
web.open(addr)
chooser.destroy()
wbuffer = textview.get_buffer()
while 1:
text = wbuffer.get_text(wbuffer.get_start_iter(), wbuffer.get_end_iter())
time.sleep(1)
openfile = open(filename,"w")
openfile.write(text)
openfile.close()