我有這個(gè)基本的“測(cè)試”應(yīng)用程序,我想在它執(zhí)行長(zhǎng)時(shí)間啟動(dòng)過(guò)程(具有數(shù)據(jù)庫(kù)請(qǐng)求的函數(shù))時(shí)顯示一個(gè)微調(diào)器,讓用戶知道它不是在竊聽(tīng)而是在啟動(dòng)。我在其他帖子中讀到可以用Gtk.events_pending()函數(shù)來(lái)做到這一點(diǎn),但我不知道如何/在哪里使用它。我嘗試了很多方法,但主窗口始終僅在請(qǐng)求完成時(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 文件,我將在其中管理一個(gè)類(lèi)中的所有請(qǐng)求(我不知道它是否編碼良好,因?yàn)槲覄倓偘l(fā)現(xiàn)了多線程。但它確實(shí)有效):#!/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