I am a beginner programmer and have been learning about how to use Java since February 2015 of this year. However, I just started learning how to write code in the Python Language, a few weeks ago and find it to be much easier to work with. My goal here is to create a simple Note pad program from scratch using Python and I need assistance please. This will be my first full program created! I want to get my feet wet, and get used to writing programs so that I can possibly do Freelance work/projects.I have wrote some code to make a GUI box with dropdown menus such as a File, Edit, Format, View, and Help menu. However, I am stuck on how to get an event to happen when a button is clicked on. Can anyone take a look at my code and possibly give me some suggestions? I posted my code on Github.

My github link is https://github.com/pjohnsn/NotepadPRG

Feel free to add code to make my program interact with user input! Thank you in advance.

Generally:

import wx

class MyEvents(object):
    """separate events into this class"""
    def __init__(self, parent):
        self = parent

    def button1Click(self, event):
        self.label.SetLabel("Button1 left clicked")

    def button2Click(self, event):
        self.label.SetLabel("Button2 left clicked!!!")


class MyFrame(wx.Frame, MyEvents):
    """MyFrame inherits wx.Frame and MyEvents"""
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        # create buttons and bind them to event
        self.button1 = wx.Button(self, wx.ID_ANY, label='Button1')
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

        self.button2 = wx.Button(self, wx.ID_ANY, label='Button2')
        self.button2.Bind(wx.EVT_BUTTON, self.button2Click)

        # create label to show result
        self.label = wx.StaticText(self, wx.ID_ANY, "", size=(150, -1))

        # for layout use box sizer
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.button2, 0, flag=wx.ALL, border=10)
        sizer_v.Add(self.label, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)


app = wx.App(0)
mysize = (260, 170)
# creates MyFrame instance and shows the frame
MyFrame(None, 'Event Inherit Test', mysize).Show()
app.MainLoop()
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.