为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 Gtk.events_pending?

如何使用 Gtk.events_pending?

ibeautiful 2021-06-11 18:39:32
我有这个基本的“测试”应用程序,我想在它执行长时间启动过程(具有数据库请求的函数)时显示一个微调器,让用户知道它不是在窃听而是在启动。我在其他帖子中读到可以用Gtk.events_pending()函数来做到这一点,但我不知道如何/在哪里使用它。我尝试了很多方法,但主窗口始终仅在请求完成时显示:这是主要的 .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 文件,我将在其中管理一个类中的所有请求(我不知道它是否编码良好,因为我刚刚发现了多线程。但它确实有效):#!/usr/bin/python3# -*- coding: Utf-8 -*-import os.path, DBimport concurrent.futurespath = os.path.dirname(os.path.realpath(__file__))
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 104 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号