Hi Guys,

I've been doing python programming for a few months and I have some code that needs a GUI. All the code does is various print outs to the screen, now in my head this sounds simple enough to convert to a GUI but I can't figure out where my actual code goes!

I have my frame with a txtctrl , all I need to do is .SetValue instead of print in my code I think but where does my existing code fit into the GUI code?

for example:

my frame is :

#!/usr/bin/python
import wx
class MyFrame(wx.Frame):


	def __init__(self, parent, title):
		wx.Frame.__init__(self, parent, title=title, size=(200,100))
		self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
		self.Show(True)
		 
app = wx.App(False)
frame = MyFrame(None, 'Example')
app.MainLoop()

my existing code is:

#!/usr/bin/python
printthis = 0

while 1:
	printthis+= 1
	print printthis

How would I put the 2 together?

(OS: Linux, GUI kit: WxPython, Python Version: 2.6)

Cheers,

Like this it can be done,did some changes in your code that generate a infinity loop.
Read stiky post about GUI in top on this forum.
http://zetcode.com/

import wx

class MyFrame(wx.Frame):
    '''info about class | doc_string'''
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        #---|Window color|---#
        self.SetBackgroundColour('light blue')

        #---|Panel for frame|---#
        self.panel = wx.Panel(self)

        #---|Button|---#
        self.button1 = wx.Button(self.panel, -1, "Click", (100,35))
        self.Bind(wx.EVT_BUTTON, self.EvtChoice,self.button1) #***

        #---|Static Text|---#
        self.text = wx.StaticText(self.panel, -1, '', pos=(100,70))

    #Your code this is called event handling
    def EvtChoice(self, event): #***
        '''print out 10 numbers'''
        printthis = 0
        my_list = []
        while True:
            printthis += 1
            my_list.append(printthis)
            make_string = [str(x) for x in my_list]
            self.text.SetLabel(' '.join(make_string))
            #print printthis   # You dont use print in GUI,it can be ok for troubleshooting
            if printthis == 10:
                return False

if __name__ == "__main__":
    app = wx.App()
    mytitle = 'My window'
    width = 300
    height = 200
    MyFrame(None, mytitle, (width, height)).Show()
    app.MainLoop()

Hey, thanks for that! I feel pretty stupid now... I had already read most of the tutorials out there including the website you link to but didn't understand about events lol

I think what I need looking at your example is my code to run when the event "EVT_SHOW" happens (when the frame is loaded?)

kind of like the "OnLoad" section in visual basic :-O

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.