I need help with a program I am making it creates window but doesn't display buttons aor text controls

import wx
import MySQLdb

db = MySQLdb.connect(host="localhost", user="root", passwd="Hornets71", db="soul_society")
cursor = db.cursor()

class MainWin(wx.Frame):
    def reg():
    number = self.numtxtctrl.GetLineText()
    name = self.nametxtctrl.GetLineText()
    uid = self.uidtxtctrl.GetLineText()
    cursor.execute("INSERT INTO member_list (number, name, uid) VALUES(%s, %s, %s)", (number, name, uid))
    db.commit()
    
    
    
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.numtxtxctrl = wx.TextCtrl(self, -1, "Put User # Here")
        self.nametxtctrl = wx.TextCtrl(self, -1, "Put User Name Here")
        self.uidtxtctrl = wx.TextCtrl(self, -1, "Put User's Unique ID Here")
        self.regbutton = wx.Button(self, -1, "Register")
        self.canbutton = wx.Button(self, -1, "Cancel")
        
        self.regbutton.Bind(wx.EVT_BUTTON, self.reg)
        self.canbutton.Bind(wx.EVT_BUTTON, self.numtxtctrl.Clear)
        self.canbutton.Bind(wx.EVT_BUTTON, self.nametxtctrl.Clear)
        self.canbutton.Bind(wx.EVT_BUTTON, self.uidtxtctrl.Clear)
        
        self.__set_properties()
        self.__do_layout()
    
    def __set_properties(self):
        self.SetTitle("Soul Society Recruiter Registration")
    
    def __do_layout(self):
        sizer = wx.FlexGridSizer(3, 3, 0, 0)
        sizer.Add(self.numtxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.nametxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.uidtxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.regbutton, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.canbutton, 0, wx.ADJUST_MINSIZE, 0)
        self.SetAutoLayout(TRUE)
        self.SetSizer(sizer)
        sizer.Fit(self)
        sizer.SetSizeHints(self)
        self.Layout()

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    MainWin = MainWin(None, -1, "")
    app.SetTopWindow(MainWin)
    MainWin.Show()
    app.MainLoop()

Recommended Answers

All 3 Replies

What is MySQLdb?

Obviously something wrong in your MainWin class.
Maybe the missing indents in reg()?
Do you get any traceback error?
Change line
app = wx.PySimpleApp(0)
to
app = wx.PySimpleApp(redirect = True)


I don't have MySQLdb installed, so I can't help you much.

This was old, but I was searching for wxPython stuff and found this ...

The code is 'fixed' wrt displaying windows. Still To-Do for anyone who wants,

(1) get the sql code to work
(2) get the callbacks to work.

Jeff

import wx
#import MySQLdb

#db = MySQLdb.connect(host="localhost", user="root", passwd="Hornets71", db="soul_society")
#cursor = db.cursor()

class MainWin(wx.Frame):
    
    
    
    
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.numtxtctrl = wx.TextCtrl(self, -1, "Put User # Here")
        self.nametxtctrl = wx.TextCtrl(self, -1, "Put User Name Here")
        self.uidtxtctrl = wx.TextCtrl(self, -1, "Put User's Unique ID Here")
        self.regbutton = wx.Button(self, -1, "Register")
        self.canbutton = wx.Button(self, -1, "Cancel")
        
        self.regbutton.Bind(wx.EVT_BUTTON, self.reg)
        self.canbutton.Bind(wx.EVT_BUTTON, self.numtxtctrl.Clear)
        self.canbutton.Bind(wx.EVT_BUTTON, self.nametxtctrl.Clear)
        self.canbutton.Bind(wx.EVT_BUTTON, self.uidtxtctrl.Clear)
        
        self.__set_properties()
        self.__do_layout()

    def reg():
        number = self.numtxtctrl.GetLineText()
        name = self.nametxtctrl.GetLineText()
        uid = self.uidtxtctrl.GetLineText()
        cursor.execute("INSERT INTO member_list (number, name, uid) VALUES(%s, %s, %s)", (number, name, uid))
        db.commit()
    
    def __set_properties(self):
        self.SetTitle("Soul Society Recruiter Registration")
    
    def __do_layout(self):
        sizer = wx.FlexGridSizer(3, 3, 0, 0)
        sizer.Add(self.numtxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.nametxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.uidtxtctrl, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.regbutton, 0, wx.ADJUST_MINSIZE, 0)
        sizer.Add(self.canbutton, 0, wx.ADJUST_MINSIZE, 0)
        self.SetAutoLayout(True)
        self.SetSizer(sizer)
        sizer.Fit(self)
        sizer.SetSizeHints(self)
        self.Layout()

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    MainWin = MainWin(None, -1, "")
    app.SetTopWindow(MainWin)
    MainWin.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.