我想在python对话框内, 设置一个按钮, 点击按钮, 就刷新一下内容,如何做?

#  ------ 自编 Item101 模块-----------------
import wx
import random
from Opera_SingleSelect_db import *

#--------------  菜单item101   ---------------------------
class myItem101(wx.Dialog):
    def __init__(self,*args):  # 初始化对话框
        wx.Dialog.__init__(self, None, -1,
                           '工程监测专业从业人员技术能力评估平台',
                           pos=(200, 50),
                           size = (350, 450))
        #parent = self.GetParent()
        self.panel = wx.Panel(parent=self)

#-------------第一行 ---------------
        mylabel = "欢迎:"+ args[0]
        self.title = wx.StaticText(self.panel, label=mylabel, pos=(20,20))

#-------------第二行 --------------
        font = wx.Font(11, wx.DEFAULT, wx.NORMAL, wx.BOLD, False)
        self.label1 = wx.StaticText(self.panel, label="| 单选题:                1/10", pos=(20,60))
        self.label1.SetFont(font)
#-------------第三行 --------------
        #把数据库信息读入
        bb = random.randint(1, 8)
        aa = get_SingleSelectDB_list(str(bb), DBFILE)
        global items
        items = []
        for i in aa[0]:
            items.append(i)
        #设置第三行(考题)
        self.label2 = wx.StaticText(self.panel, label=items[0], pos=(20,90))

# -------------第四行 --------------
        self.SelectA = wx.Button(self.panel, wx.ID_ANY, items[1])
        self.SelectB = wx.Button(self.panel, wx.ID_ANY, items[2])
        self.SelectC = wx.Button(self.panel, wx.ID_ANY, items[3])
        self.SelectD = wx.Button(self.panel, wx.ID_ANY, items[4])
# -------------空行 ---------------
        self.BANK = wx.StaticText(self.panel, label='     ', pos=(20, 20))

# -------------第六行  按钮行--------------
        exitBtn = wx.Button(self.panel, wx.ID_ANY, '退出')
        NextBtn = wx.Button(self.panel, wx.ID_ANY, '下一题')
# -------------布局--------------

        topSizer = wx.BoxSizer(wx.VERTICAL)
        H1_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        H1_Sizer.Add(self.title, 0, wx.ALL, 5)

        H2_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        H2_Sizer.Add(self.label1, 0, wx.ALL, 5)

        H3_Sizer = wx.BoxSizer(wx.HORIZONTAL)
        H3_Sizer.Add(self.label2, 0, wx.ALL, 5)

        Buttons = wx.BoxSizer(wx.HORIZONTAL)
        Buttons.Add(exitBtn, 0, wx.ALL, 8)
        Buttons.Add(NextBtn, 0, wx.ALL, 8)

        topSizer.Add(H1_Sizer, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(H2_Sizer, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(H3_Sizer, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(self.SelectA, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(self.SelectB, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(self.SelectC, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(self.SelectD, 0, wx.ALL | wx.LEFT, 5)

        topSizer.Add(self.BANK, 0, wx.ALL | wx.LEFT, 5)
        topSizer.Add(Buttons, 0, wx.ALL | wx.CENTER, 5)

        self.panel.SetSizer(topSizer)
        topSizer.Fit(self)
#--------------  绑定事件  ----------------------------------------
        self.Bind(wx.EVT_BUTTON, self.On_SelectA, self.SelectA)
        self.Bind(wx.EVT_BUTTON, self.On_SelectB, self.SelectB)
        self.Bind(wx.EVT_BUTTON, self.On_SelectC, self.SelectC)
        self.Bind(wx.EVT_BUTTON, self.On_SelectD, self.SelectD)
        self.Bind(wx.EVT_BUTTON, self.onExit, exitBtn)
        self.Bind(wx.EVT_BUTTON, self.onNextBtn, NextBtn)

        self.Update()

    def On_SelectA(self, event):
        if items[5] == "A": wx.MessageBox('答案正确!')
        else:
            wx.MessageBox('答案错误!')
            self.SelectA.Disable()
        return "A"

    def On_SelectB(self, event):
        if items[5] == "B": wx.MessageBox('答案正确!')
        else:
            wx.MessageBox('答案错误!')
            self.SelectB.Disable()
        return "B"

    def On_SelectC(self, event):
        if items[5] == "C":  wx.MessageBox('答案正确!')
        else:
            wx.MessageBox('答案错误!')
            self.SelectC.Disable()
        return "C"

    def On_SelectD(self, event):
        if items[5] == "D":  wx.MessageBox('答案正确!')

        else:
            wx.MessageBox('答案错误!')
            self.SelectD.Disable()
        return "D"

    def onExit(self,event):
        self.Close(True)  # 关闭顶层框架窗口

    def onNextBtn(self,event):    #????
        self.UpdateWindow()       #????

if __name__ == '__main__':
    app = wx.App()
    dialog = myItem101("张三")
    dialog.SetIcon(wx.Icon('C:\\Users\\86139\\Desktop\\shuaipy04\\3.ICO',
                           wx.BITMAP_TYPE_ICO))
    dialog.Show()
    app.MainLoop()

首先要重新读取数据,然后通过控件的方法把数据设置到控件中。这样就刷新了。

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632