【问题标题】:Creating a dynamic GUI using wxPython [duplicate]使用 wxPython 创建动态 GUI [重复]
【发布时间】:2018-12-02 20:38:30
【问题描述】:

我正在尝试使用 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()

我是新手,不知道如何从这里开始。我的目标是打印新值并删除旧值(帧)。谢谢!

【问题讨论】:

  • 为什么这个问题被否决了?我怎样才能使它变得更好?

标签: python user-interface wxpython


【解决方案1】:

对于 att 更改 wx.StaticText 标签,您可以使用 SetLabel。

对于同一类中另一个 def 的 att 调用 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。

【讨论】:

  • 谢谢!尽管我确实找到了对我有用的不同答案,但它确实与此相似。非常感谢!
  • 也许他的好主意是在评论中添加链接到您找到的解决方案以帮助其他用户或接受此答案。
猜你喜欢
  • 1970-01-01
  • 2018-10-13
  • 1970-01-01
  • 2015-09-08
  • 2013-11-19
  • 2015-08-25
  • 1970-01-01
  • 2014-02-27
相关资源
最近更新 更多