Search code examples
pythonuser-interfacewxpython

Creating a dynamic GUI using wxPython


I'm trying to create a dynamic GUI using wxPython. My aim is to constantly read values of voltage and current and refresh the window so that they're constantly updated. There can be or not be a delay between the reading of values. My code till now is as follows:

    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()

I'm new to this and don't know how to proceed from here. My aim is to print new values and delete the old values(frames). Thanks!


Solution

  • For att change wx.StaticText label you can use SetLabel.

    For att call vValue and cValue from another def in same Class you should rename them to self.vValue and 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 values should be str.