在这个脚本中,错误在哪里? 为什么对话。 destroy()不会立即关闭文件请求者 但只能在5秒后关闭它:指令时间。睡觉(5)到第41行?
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import sys, os, time
class finestra(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Titolo")
self.set_default_size(100, 100)
def selFile(self):
dialog = Gtk.FileChooserDialog("Seleziona un file", self,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_OPEN, Gtk.ResponseType.OK,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
dialog.set_default_response(Gtk.ResponseType.CANCEL)
response = dialog.run()
if response == Gtk.ResponseType.OK:
file_path = dialog.get_filename()
return file_path
dialog.destroy()
elif response == Gtk.ResponseType.CANCEL:
print("Non è stato selezionato alcun file")
dialog.destroy()
win = finestra()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
ff=win.selFile()
print(ff)
time.sleep(5)