Z
Z
ZeroTolerance782019-05-14 11:10:26
Python
ZeroTolerance78, 2019-05-14 11:10:26

How to link Python code and GUI on wxPython?

Sorry for the dumb question, I'm new. I couldn't find the answer myself. Essence of the question: there is dynamic code, for example a simple counter:

i=0
while i<10:
 print (i)
 i=i+1

and there is a wxPython window
import wx

app = wx.App()
frame = wx.Frame(None, -1, 'win.py')

panel = wx.Panel(frame, wx.ID_ANY)
text1 = wx.StaticText(panel, wx.ID_ANY, str (i), (50, 10))

frame.Show()
frame.Centre()
app.MainLoop()

How to connect them? How to make the counter run inside the window? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-05-14
@ZeroTolerance78

Through the timer, of course.
It is possible through multithreading.

import wx

i=0

def Timer1(evt):
    global text1,i
    i+=1
    text1.SetLabelText(str(i))

app = wx.App()
frame = wx.Frame(None, -1, 'win.py')
t1 = wx.Timer(frame)
t1.Start(1000)

panel = wx.Panel(frame, wx.ID_ANY)
text1 = wx.StaticText(panel, wx.ID_ANY, str(i), (50, 10))
frame.Bind(wx.EVT_TIMER, Timer1)

frame.Show()
frame.Centre()
app.MainLoop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question