如何使用 Gtk.events_pending?

我有这个基本的“测试”应用程序,我想在它执行长时间启动过程(具有数据库请求的函数)时显示一个微调器,让用户知道它不是在窃听而是在启动。我在其他帖子中读到可以用Gtk.events_pending()函数来做到这一点,但我不知道如何/在哪里使用它。我尝试了很多方法,但主窗口始终仅在请求完成时显示:


这是主要的 .py 文件:


#!/usr/bin/python3

# -*- coding: Utf-8 -*-


import gi

gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, Gdk, GdkPixbuf, GObject


import Mng,os.path


path = 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 文件,我将在其中管理一个类中的所有请求(我不知道它是否编码良好,因为我刚刚发现了多线程。但它确实有效):


#!/usr/bin/python3

# -*- coding: Utf-8 -*-

import os.path, DB

import concurrent.futures


path = os.path.dirname(os.path.realpath(__file__))

ibeautiful
浏览 105回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python