Re: Python basic window control examples?

Yes. This is a Magurp example of a simple window with a button. Note that you have to install wxpython: pip install wxpython

import wx

class MyForm(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, title="Button Press Tutorial", size=(640,480))
    #Add a panel so it looks correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
    #create a visual button and label it ok
        self.btn = wx.Button(panel, label="OK",pos=(0,0))
    #set buttons position to center of frame
        self.btn.SetPosition(((self.GetClientSize()[0]/2)-(self.btn.GetSize()[0]/2),(self.GetClientSize()[1]/2)-(self.btn.GetSize()[1]/2)))
    #bind the button press event to a function
        self.btn.Bind(wx.EVT_BUTTON, self.onBtnPress)

#when button is pressed, this function is called
    def onBtnPress(self, event):
    #check the event ID to make sure it matches the button we want
        if event.GetId() == self.btn.GetId():
            print("button pressed!")

# Run the program
if __name__ == "__main__":
    app = wx.App()
#load the frame class
    frame = MyForm()
#show it so its visible and active
    frame.Show()
    app.MainLoop()

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Patrick via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Patrick via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ambro86 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector

Reply via email to