我有這個基本的“測試”應(yīng)用程序,我想在它執(zhí)行長時間啟動過程(具有數(shù)據(jù)庫請求的函數(shù))時顯示一個微調(diào)器,讓用戶知道它不是在竊聽而是在啟動。我在其他帖子中讀到可以用Gtk.events_pending()函數(shù)來做到這一點,但我不知道如何/在哪里使用它。我嘗試了很多方法,但主窗口始終僅在請求完成時顯示:這是主要的 .py 文件:#!/usr/bin/python3# -*- coding: Utf-8 -*-import gigi.require_version('Gtk', '3.0')from gi.repository import Gtk, Gdk, GdkPixbuf, GObjectimport Mng,os.pathpath = os.path.dirname(os.path.realpath(__file__))# MAIN WINDOW ######################################################################################class PyApp: def __init__(self): builder = Gtk.Builder() builder.add_from_file(path + "/test.glade") self.obj = builder.get_object """ I would like to display on main window a spinner while doing requests. There is a self.obj('spinner') in main window, in glade file to do so. """ self.do_requests() self.obj('main').show_all() def do_requests(self): mng = Mng.Grab([ [1,'getPlayers'], [2,'getFactions'], [3,'getBoards'] ]) data = mng.grab_data() players, nb = data[1] factions, nb = data[2] boards, nb = data[3] """ Here will be the code to display data in GUI, like for example : self.obj('label_players').set_text(str(players)) """if __name__ == "__main__": app = PyApp() Gtk.main()這是 Mng.py 文件,我將在其中管理一個類中的所有請求(我不知道它是否編碼良好,因為我剛剛發(fā)現(xiàn)了多線程。但它確實有效):#!/usr/bin/python3# -*- coding: Utf-8 -*-import os.path, DBimport concurrent.futurespath = os.path.dirname(os.path.realpath(__file__))
如何使用 Gtk.events_pending?
ibeautiful
2021-06-11 18:39:32