How to write a "&" in button text in wxpython - python

This looks simple but I have not found any documentation. Tried with &&, which does not work. Want a button like this:
Button1=wx.Button(self, 5, "abc&abc", (130, 230))

Works for me with this:
import wx
class MainWindow(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title,size=(200,-1))
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.buttons = [
wx.Button(self,-1,"Button &One"),
wx.Button(self,-1,"Button &&Two"),
]
for btn in self.buttons:
self.sizer.Add(btn,1,wx.EXPAND)
self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.sizer.Fit(self)
self.Show()
app = wx.App(False)
frame = MainWindow(None,"Hello Ampersand")
app.MainLoop()

Your code working MattH but my problem is actually i was showing button in click event of menubar at that time && not works..check out below code...what should be done in such a case
import wx
class MainWindow(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title,size=(699, 570))
fileMenu= wx.Menu()
folder=wx.MenuItem(fileMenu, 1, "&Start","Click here to start..")
fileMenu.AppendItem(folder)
about = wx.MenuItem(fileMenu, 2, '&About',"Test")
fileMenu.AppendItem(about)
quit = wx.MenuItem(fileMenu, 3, '&Quit',"Terminate the program")
fileMenu.AppendItem(quit)
menuBar = wx.MenuBar()
menuBar.Append(fileMenu,"&File")
self.Bind(wx.EVT_MENU, self.ShowButton, folder)
self.SetMenuBar(menuBar)
pndSummaryButton = wx.Button(self, 3, "Button &&Two", (130, 146))
pndSummaryButton.name="pndSummary"
self.printArea2 = wx.TextCtrl(self,pos = (290, 146), size = (255, 25),style = wx.TE_READONLY)
pndSummaryButton.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL,wx.LIGHT))
self.printArea2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL,wx.LIGHT))
pndSummaryButton.SetBackgroundColour(wx.Colour(153,0,0))
pndSummaryButton.SetForegroundColour(wx.Colour(255,255,255))
pndSummaryButton.SetSize(pndSummaryButton.GetBestSize())
self.Show()
def ShowButton(self,event):
pndSummaryButton = wx.Button(self, 3, "Button &&Two", (130, 176))
pndSummaryButton.name="pndSummary1"
self.printArea2 = wx.TextCtrl(self,pos = (290, 176), size = (255, 25),style = wx.TE_READONLY)
pndSummaryButton.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL,wx.LIGHT))
self.printArea2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL,wx.LIGHT))
pndSummaryButton.SetBackgroundColour(wx.Colour(153,0,0))
pndSummaryButton.SetForegroundColour(wx.Colour(255,255,255))
pndSummaryButton.SetSize(pndSummaryButton.GetBestSize())
app = wx.App(False)
frame = MainWindow(None,"Hello Ampersand")
app.MainLoop()

Related

two BoxSizers interfere

I have two BoxSizers, the first one
sizer = wx.BoxSizer (wx.VERTICAL)
sizer.Add (self.grid2, 1, wx.EXPAND)
panel2.SetSizer (sizer)
and another vertical BoxSizers, to the left of the button grid, both BoxSizers interfere.
vbox1 = wx.FlexGridSizer (rows = 1, cols = 3, hgap = 5, vgap = 5)
buttonsBox1 = wx.BoxSizer (wx.VERTICAL)
buttonsBox1.Add (self.buttonoborved)
vbox1.Add (buttonsBox1)
vbox1.Add (self.grid2)
vbox1.Add (midPan1, wx.ID_ANY, wx.EXPAND | wx.ALL, 20)
panel2.SetSizer (vbox1)
An error occurs - Adding a window already in a sizer, detach it first!
How can they be called at the same time.
Edit:
That are two BoxSizer, one in other, but how can be put buttons in there.
import wx
import wx.grid
from wx.lib.scrolledpanel import ScrolledPanel
class TestPanel(ScrolledPanel):
def __init__(self, parent):
ScrolledPanel.__init__(self, parent, wx.ID_ANY, size=(640, 480))
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self._create_table(), 1, wx.EXPAND | wx.ALL, 5)
self.SetSizer(self.sizer)
self.SetupScrolling()
self.SetAutoLayout(1)
def _create_table(self):
_table = wx.grid.Grid(self, -1)
_table.CreateGrid(0, 2)
for i in range(1723): # Work normally If I use 1722 rows
_table.AppendRows()
_table.SetCellValue(i, 0, str(i))
return _table
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
title="Scroll table", size=(640, 480))
self.fSizer = wx.BoxSizer(wx.VERTICAL)
self.fSizer.Add(TestPanel(self), 1, wx.EXPAND)
self.SetSizer(self.fSizer)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = TestFrame()
app.MainLoop()
It depends where you want to place the buttons but let's assume they should be at the bottom.
import wx
import wx.grid
from wx.lib.scrolledpanel import ScrolledPanel
class TestPanel(ScrolledPanel):
def __init__(self, parent):
ScrolledPanel.__init__(self, parent, wx.ID_ANY, size=(640, 480))
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self._create_table(), 1, wx.EXPAND | wx.ALL, 5)
self.b1 = wx.Button(self, -1, "Button 1")
self.b2 = wx.Button(self, -1, "Button 2")
self.b3 = wx.Button(self, -1, "Button 3")
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
button_sizer.Add(self.b1)
button_sizer.Add(self.b2)
button_sizer.Add(self.b3)
self.sizer.Add(button_sizer)
self.SetSizer(self.sizer)
self.SetupScrolling()
self.SetAutoLayout(1)
def _create_table(self):
_table = wx.grid.Grid(self, -1)
_table.CreateGrid(0, 2)
for i in range(1723): # Work normally If I use 1722 rows
_table.AppendRows()
_table.SetCellValue(i, 0, str(i))
return _table
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
title="Scroll table", size=(640, 480))
self.fSizer = wx.BoxSizer(wx.VERTICAL)
self.fSizer.Add(TestPanel(self), 1, wx.EXPAND)
self.SetSizer(self.fSizer)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = TestFrame()
app.MainLoop()

TextCtrl doesn't work properly with CheckBox

I wrote a code to receive some input data from user using both CheckBox and TextCtrl. The problem is when I marked the checkbox and textctrl appears, it accept to receive input data, but won't replace with the default one!
import wx
class mainClass(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Interface', size=(500, 250))
self.panel = wx.Panel(self)
self.checkReplaceJob = wx.CheckBox(self.panel, -1, "Replace data", (35, 60), (235, 20))
self.Bind(wx.EVT_CHECKBOX, self.replaceJob, self.checkReplaceJob)
self.RunBut = wx.Button(self.panel, -1, "Run", pos=(150, 150))
self.Bind(wx.EVT_BUTTON, self.RunClick, self.RunBut)
self.RunBut.SetDefault()
self.CloseBut = wx.Button(self.panel, -1, "Close", pos=(250, 150))
self.Bind(wx.EVT_BUTTON, self.CloseClick, self.CloseBut)
def CloseClick(self, event):
self.Close()
def replaceJob(self, event):
if(self.checkReplaceJob.IsChecked()):
self.repJobRetName()
self.btn = wx.Button(self.panel, wx.ID_ANY, "&Help", pos=(345, 82))
self.Bind(wx.EVT_BUTTON, self.HelpJobName, self.btn)
def repJobRetName(self):
self.label = wx.StaticText(self.panel, -1, label = "New name:", pos=(165,87))
self.entry = wx.TextCtrl(self.panel, -1, value = u"Task-1", pos=(230, 84))
repJobName = self.entry.GetValue()
return repJobName
def HelpJobName(self, event):
help = 'Write out new name.'
wx.MessageBox(help, "Help")
def RunClick(self, event):
if(self.checkReplaceJob.IsChecked()):
replaceName = self.repJobRetName()
wx.MessageBox('The new name is: ' + replaceName, "Info")
#############=======================
if __name__ == "__main__":
app = wx.App(False)
mainClass().Show()
app.MainLoop()
Let me make sure I understand correctly. You want the text control to have a default value when it is created, but you want that value to disappear when you actually select the control. Is that correct? If so, then you just need to add a binding to wx.EVT_SET_FOCUS and do a little work when the widget gets focus. Here's an example:
import wx
class mainClass(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Interface', size=(500, 250))
self.panel = wx.Panel(self)
self.checkReplaceJob = wx.CheckBox(self.panel, -1, "Replace data", (35, 60), (235, 20))
self.Bind(wx.EVT_CHECKBOX, self.replaceJob, self.checkReplaceJob)
self.RunBut = wx.Button(self.panel, -1, "Run", pos=(150, 150))
self.Bind(wx.EVT_BUTTON, self.RunClick, self.RunBut)
self.RunBut.SetDefault()
self.CloseBut = wx.Button(self.panel, -1, "Close", pos=(250, 150))
self.Bind(wx.EVT_BUTTON, self.CloseClick, self.CloseBut)
def CloseClick(self, event):
self.Close()
def replaceJob(self, event):
if(self.checkReplaceJob.IsChecked()):
self.repJobRetName()
self.btn = wx.Button(self.panel, wx.ID_ANY, "&Help", pos=(345, 82))
self.Bind(wx.EVT_BUTTON, self.HelpJobName, self.btn)
def repJobRetName(self):
self.label = wx.StaticText(self.panel, -1, label = "New name:", pos=(165,87))
self.entry = wx.TextCtrl(self.panel, -1, value = u"Task-1", pos=(230, 84))
self.entry.Bind(wx.EVT_SET_FOCUS, self.onFocus)
repJobName = self.entry.GetValue()
return repJobName
def onFocus(self, event):
current_value = self.entry.GetValue()
if current_value == "Task-1":
self.entry.SetValue("")
def HelpJobName(self, event):
help = 'Write out new name.'
wx.MessageBox(help, "Help")
def RunClick(self, event):
if(self.checkReplaceJob.IsChecked()):
replaceName = self.repJobRetName()
wx.MessageBox('The new name is: ' + replaceName, "Info")
#############=======================
if __name__ == "__main__":
app = wx.App(False)
mainClass().Show()
app.MainLoop()

creating a wxpython scrolled window (frame) by an event

I am trying to create a new frame in a wxpanel by clicking a button.
Below is my code.
It does not work.
Scroll bars do not show up.
Can anyone help me? Thanks!
(update: A button is added in the new window)
import wx
class ftest(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"test Panel", size=(800, 500), pos=(0,0))
self.MainPanel = wx.Panel(self, wx.ID_ANY)
self.btn1 = wx.Button(self.MainPanel, pos=(50,100), label="New Frame")
self.btn1.Bind(wx.EVT_BUTTON, self.newFrame)
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', size=(500, 500), pos=(800,0))
self.new_window.Show()
self.scroll = wx.ScrolledWindow(self.new_window, -1)
self.scroll.SetScrollbars(1, 1, 1600, 1400)
self.btn2 = wx.Button(self.new_window, pos=(50,100), label="button2")
if __name__ == "__main__":
app = wx.App(False)
frame = ftest()
frame.Show()
app.MainLoop()
,
(update 2)
based on Joran Beasley's code,
this code creates scroll bars, but the button2 is not shown.
and the text widget does not work properly when scrolled.
import wx
class ftest(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"test Panel", size=(800, 500), pos=(0,0))
self.MainPanel = wx.Panel(self, wx.ID_ANY)
self.btn1 = wx.Button(self.MainPanel, pos=(50,100), label="New Frame")
self.btn1.Bind(wx.EVT_BUTTON, self.newFrame)
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', pos=(800,0))
self.scroll = wx.ScrolledWindow(self.new_window, -1,size=(500,500))
self.scroll.SetScrollbars(1, 1, 1600, 1400)
self.new_window.Layout()
self.new_window.Fit()
self.new_window.Show()
self.btn2 = wx.Button(self.new_window, pos=(50,100), label="button2")
wx.StaticText(self.new_window, -1, 'test text', pos=(50, 200))
if __name__ == "__main__":
app = wx.App(False)
frame = ftest()
frame.Show()
app.MainLoop()
,
(update 3)
I found my mistake. The widgets should be on the scroll object, not on the frame object.
Layout() and Fit() are not required.
so correct code is
import wx
class ftest(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"test Panel", size=(800, 500), pos=(0,0))
self.MainPanel = wx.Panel(self, wx.ID_ANY)
self.btn1 = wx.Button(self.MainPanel, pos=(50,100), label="New Frame")
self.btn1.Bind(wx.EVT_BUTTON, self.newFrame)
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', pos=(800,0),size=(500,500))
self.scroll = wx.ScrolledWindow(self.new_window, -1)
self.scroll.SetScrollbars(1, 1, 1600, 1400)
#self.new_window.Layout()
#self.new_window.Fit()
self.new_window.Show()
self.btn2 = wx.Button(self.scroll, pos=(50,100), label="button2")
wx.StaticText(self.scroll, -1, 'test text', pos=(50, 200))
if __name__ == "__main__":
app = wx.App(False)
frame = ftest()
frame.Show()
app.MainLoop()
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', size=(500, 500), pos=(800,0))
self.scroll = wx.ScrolledWindow(self.new_window, -1)
self.scroll.SetScrollbars(1, 1, 1600, 1400)
self.new_window.Layout()
self.new_window.Fit()
self.new_window.Show()
you need to layout the new window ... since you clearly want it to fill the 500,500 area you will need to use sizers
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', size=(500, 500), pos=(800,0))
sz = wx.BoxSizer()
sz.SetMinSize((500,500)) #force minimum size
self.scroll = wx.ScrolledWindow(self.new_window, -1)
sz.Add(self.scroll,1,wx.EXPAND)
self.scroll.SetScrollbars(1, 1, 1600, 1400)
self.new_window.SetSizer(sz)
self.new_window.Layout()
self.new_window.Fit()
self.new_window.Show()
or just force the size of the contained scrollwindow (which is what you normally do for scrolled windows)
def newFrame(self, event):
self.new_window = wx.Frame(self, title='frame2', pos=(800,0))
self.scroll = wx.ScrolledWindow(self.new_window, -1,size=(500,500))
self.scroll.SetScrollbars(1, 1, 1600, 1400)
self.new_window.Layout()
self.new_window.Fit()
self.new_window.Show()

wxPython StaticText Issue in my Code

There's an issue in this bit of wxPython code I have, the StaticText causes everything else to seemingly disappear.
Note: This is my first time using wxPython and I'm very novice at programming in general, so please try to give a clear explanation. Thanks!
import wx
APP_EXIT = 1
pos1 = (150, 200)
class scoutingSet(wx.Frame):
def __init__(self, *args, **kwargs):
super(scoutingSet, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
############################################################
# MENUBARS AND MENUITEMS
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
fileMenu2 = wx.Menu()
openSheet = wx.MenuItem(fileMenu, wx.ID_ANY, 'Open')
openSheet.SetBitmap(wx.Bitmap('open.png'))
fileMenu.AppendItem(openSheet)
fileMenu.AppendSeparator()
saveSheet = wx.MenuItem(fileMenu, wx.ID_ANY, 'Save')
saveSheet.SetBitmap(wx.Bitmap('save.png'))
fileMenu.AppendItem(saveSheet)
fileMenu.AppendSeparator()
quitSheet = wx.MenuItem(fileMenu, APP_EXIT, 'Quit')
quitSheet.SetBitmap(wx.Bitmap('close.png'))
fileMenu.AppendItem(quitSheet)
self.Bind(wx.EVT_MENU, self.OnQuit, id=APP_EXIT)
fileMenu2.Append(100, '&About')
self.Bind(wx.EVT_MENU, self.aboutBox, id=100)
menuBar.Append(fileMenu, 'File')
menuBar.Append(fileMenu2, 'Information')
self.SetMenuBar(menuBar)
############################################################
# BUTTONS AND CONTROL
panel = wx.Panel(self)
closebutton = wx.Button(panel, label = 'Close\nClose', pos = (20, 30))
closebutton.Bind(wx.EVT_BUTTON, self.OnQuit)
############################################################
# STATIC TEXTS
############################################################
# TEXT CONTROL BOXES
wx.TextCtrl(panel, pos = pos1, size = (50, 50))
wx.TextCtrl(panel, pos = (300, 400), size = (50, 50))
############################################################
# SETTINGS
self.stuff(self)
self.Maximize()
self.SetTitle('Scouting Sheet')
self.Centre()
self.Show(True)
############################################################
# Quitting
def OnQuit(self, e):
self.Close()
# Info in
def aboutBox(self, e):
desc = """This is the SOTAbots 2014 scouting sheet for the FRC 2014 game Aerial Assist"""
infoInAbout = wx.AboutDialogInfo()
infoInAbout.SetIcon(wx.Icon('scouting.png', wx.BITMAP_TYPE_PNG))
infoInAbout.SetName('Scouting Sheet')
infoInAbout.SetVersion('1.0')
infoInAbout.SetDescription(desc)
infoInAbout.AddDeveloper('Franklin Lyon\nLucas Grillos')
wx.AboutBox(infoInAbout)
def stuff(self, e):
textpnl = wx.StaticText(self,-1 , label='Watermark', pos=(20, 30))
textpnl.SetForegroundColour('white')
textpnl.SetBackgroundColour('blue')
def main():
ex = wx.App()
scoutingSet(None)
ex.MainLoop()
if __name__ == '__main__':
main()
Note: I put the Static Text in a function, but even inside the InitUI function, the issue persists. It has to do with the StaticText being shown because if I comment out the call everything displays fine.
Thanks in advance.
I think wx.StaticText is put on self (wx.Frame) rather than the panel, although wx.TextCtrl are on the panel. What happens if you put wx.StaticText on the panel?
Also, I think you need a Sizer (ex. wx.BoxSizer) to manage the layout. You can find a tutorial about wx.BoxSizer at http://zetcode.com/wxpython/layout/. In initUI, I will do something like:
txtctrl1 = wx.TextCtrl(panel, pos = pos1, size = (50, 50))
txtctrl2 = wx.TextCtrl(panel, pos = (300, 400), size = (50, 50))
textpnl = wx.StaticText(panel,-1 , label='Watermark', pos=(20, 30))
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.add(txtctrl1, 1, wx.EXPAND | wx.ALL, 5)
vbox.add(txtctrl2, 1, wx.EXPAND | wx.ALL, 5)
vbox.add(textpnl , 1, wx.EXPAND | wx.ALL, 5)
vbox.add(closebutton, 0, wx.EXPAND | wx.ALL, 5)
panel.SetSizer(vbox)
i hope it helps.
You GUI components are not properly laid out. I recommend you to use sizers for a proper layout. BoxSizer are simple to play with. Here is a nice tutorial on Layout management.
Your code will work when you provide the size of the panel. Use this line panel = wx.Panel(self, -1, size=(800,800)) now you shall see all your components! I also changed the position of your static text, because it was being overlapped with the button.
Please note that you should discourage using names like panel in your code. Instead use something like myPanel or panelA etc.
Working code: Tested on Windows 8, wxPython v3.0
import wx
APP_EXIT = 1
pos1 = (150, 200)
class scoutingSet(wx.Frame):
def __init__(self, *args, **kwargs):
super(scoutingSet, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
############################################################
# MENUBARS AND MENUITEMS
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
fileMenu2 = wx.Menu()
openSheet = wx.MenuItem(fileMenu, wx.ID_ANY, 'Open')
openSheet.SetBitmap(wx.Bitmap('open.png'))
fileMenu.AppendItem(openSheet)
fileMenu.AppendSeparator()
saveSheet = wx.MenuItem(fileMenu, wx.ID_ANY, 'Save')
saveSheet.SetBitmap(wx.Bitmap('save.png'))
fileMenu.AppendItem(saveSheet)
fileMenu.AppendSeparator()
quitSheet = wx.MenuItem(fileMenu, APP_EXIT, 'Quit')
quitSheet.SetBitmap(wx.Bitmap('close.png'))
fileMenu.AppendItem(quitSheet)
self.Bind(wx.EVT_MENU, self.OnQuit, id=APP_EXIT)
fileMenu2.Append(100, '&About')
self.Bind(wx.EVT_MENU, self.aboutBox, id=100)
menuBar.Append(fileMenu, 'File')
menuBar.Append(fileMenu2, 'Information')
self.SetMenuBar(menuBar)
############################################################
# BUTTONS AND CONTROL
panel = wx.Panel(self, -1, size=(800,800))
closebutton = wx.Button(panel, label = 'Close\nClose', pos = (20, 30))
closebutton.Bind(wx.EVT_BUTTON, self.OnQuit)
############################################################
# STATIC TEXTS
############################################################
# TEXT CONTROL BOXES
wx.TextCtrl(panel, pos = pos1, size = (50, 50))
wx.TextCtrl(panel, pos = (300, 400), size = (50, 50))
############################################################
# SETTINGS
self.stuff(self)
self.Maximize()
self.SetTitle('Scouting Sheet')
self.Centre()
self.Show(True)
############################################################
# Quitting
def OnQuit(self, e):
self.Close()
# Info in
def aboutBox(self, e):
desc = """This is the SOTAbots 2014 scouting sheet for the FRC 2014 game Aerial Assist"""
infoInAbout = wx.AboutDialogInfo()
infoInAbout.SetIcon(wx.Icon('scouting.png', wx.BITMAP_TYPE_PNG))
infoInAbout.SetName('Scouting Sheet')
infoInAbout.SetVersion('1.0')
infoInAbout.SetDescription(desc)
infoInAbout.AddDeveloper('Franklin Lyon\nLucas Grillos')
wx.AboutBox(infoInAbout)
def stuff(self, e):
textpnl = wx.StaticText(self,-1 , label='Watermark', pos=(100, 100))
textpnl.SetForegroundColour('white')
textpnl.SetBackgroundColour('blue')
def main():
ex = wx.App()
scoutingSet(None)
ex.MainLoop()
if __name__ == '__main__':
main()
I hope this was helpful.

wxPython display a login box

I'm trying to build a small application in wxPython (absolute beginner) in which I display a login box before showing the content. I created a frame, inside the frame a panel with a flexigrid to put the login form inside but it doesn't show. If I launch the application the login form is invisible. If I resize the application the login box shows. Any idea why? Here's my code so far:
import wx
class AP_App(wx.App):
def OnInit(self):
frame = AP_MainFrame("Test application", (0, 0), (650, 350))
frame.Show()
self.SetTopWindow(frame)
loginPanel = AP_LoginPanel(frame)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
return True
def OnCloseWindow(self, event):
self.Destroy()
class AP_MainFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
self.CreateStatusBar()
class AP_LoginPanel(wx.Panel):
def __init__(self, frame):
self.panel = wx.Panel(frame)
self.frame = frame
self.frame.SetStatusText("Authentification required!")
self.showLoginBox()
def showLoginBox(self): #Create the sizer
sizer = wx.FlexGridSizer(rows = 3, cols = 2, hgap = 5, vgap = 15)
# Username
self.txt_Username = wx.TextCtrl(self.panel, 1, size = (150, -1))
lbl_Username = wx.StaticText(self.panel, -1, "Username:")
sizer.Add(lbl_Username,0, wx.LEFT|wx.TOP| wx.RIGHT, 50)
sizer.Add(self.txt_Username,0, wx.TOP| wx.RIGHT, 50)
# Password
self.txt_Password = wx.TextCtrl(self.panel, 1, size=(150, -1), style=wx.TE_PASSWORD)
lbl_Password = wx.StaticText(self.panel, -1, "Password:")
sizer.Add(lbl_Password,0, wx.LEFT|wx.RIGHT, 50)
sizer.Add(self.txt_Password,0, wx.RIGHT, 50)
# Submit button
btn_Process = wx.Button(self.panel, -1, "&Login")
self.panel.Bind(wx.EVT_BUTTON, self.OnSubmit, btn_Process)
sizer.Add(btn_Process,0, wx.LEFT, 50)
self.panel.SetSizer(sizer)
def OnSubmit(self, event):
UserText = self.txt_Username.GetValue()
PasswordText = self.txt_Password.GetValue()
if __name__ == '__main__':
app = AP_App()
app.MainLoop()
I just discovered I'm calling frame.Show() too soon. :)

Categories

Resources