使用wxPython创建动态GUI

时间:2018-06-23 17:46:30

标签: python user-interface wxpython

我正在尝试使用wxPython创建动态GUI。我的目的是不断读取电压和电流值并刷新窗口,以便它们不断更新。读取值之间可以有或没有延迟。到目前为止,我的代码如下:

    import wx
    import time as sleep

    class windowClass(wx.Frame):
        def __init__(self, parent, title):
            super(windowClass, self).__init__(parent, title = title, size = (200, 71))
            self.Centre()
            self.Show()
            self.basicGUI()

        def basicGUI(self):


   V = input('Enter V: ')
        C = input('Enter C: ') 
        panel = wx.Panel(self)
        Voltage = wx.StaticText(panel, -1, "Voltage: ", (3, 3))
        Current = wx.StaticText(panel, -1, "Current: ", (3, 23))
        vValue = wx.StaticText(panel, -1, str(V), (70, 3))
        cValue = wx.StaticText(panel, -1, str(C), (70, 23))

    app = wx.App()
    windowClass(None, title = 'Output Window')
    app.MainLoop()

我对此并不陌生,不知道如何从这里开始。我的目的是打印新值并删除旧值(框架)。谢谢!

1 个答案:

答案 0 :(得分:1)

要更改wx.StaticText标签,可以使用SetLabel。

要从同一类的另一个def调用vValue和cValue,应将它们重命名为self.vValue和self.cValue。

def basicGUI(self):
    V = input('Enter V: ')
    C = input('Enter C: ') 
    panel = wx.Panel(self)
    self.Voltage = wx.StaticText(panel, -1, "Voltage: ", (3, 3))
    self.Current = wx.StaticText(panel, -1, "Current: ", (3, 23))
    self.vValue = wx.StaticText(panel, -1, str(V), (70, 3))
    self.cValue = wx.StaticText(panel, -1, str(C), (70, 23))

    #delete inputed values and set new ex. 66,77
    self.update(66,77)

def update(self,V,C):
    self.vValue.SetLabel(str(V))
    self.cValue.SetLabel(str(C))

Setlabel的值应为str。