0
我正在學習ui python並嘗試使用wxpython進行UI開發(也沒有UI exp)。我已經能夠創建一個面板,一個按鈕和一個文本輸入框的框架。我想把所有這些放在屏幕的中心位置,以便我可以實現其餘的功能。目前他們是重疊的想要使用wxpython添加一個文本框和按鈕和靜態字段在屏幕中心的圖像?幫助我不要重疊和放置
class KartScan(wx.Panel):
""" create a panel with a canvas to draw on"""
def __init__(self, parent):
wx.Panel.__init__(self, parent, wx.ID_ANY)
# pick a .jpg, .png, .gif, or .bmp wallpaper image file you
# have in the working folder or give full path
image_file = 'index.png'
self.bmp = wx.Bitmap(image_file)
# this 50ms delay is needed to allow image loading first
# may have to increase delay for very large images
wx.FutureCall(50, self.make_canvas)
# react to a resize event and redraw image
wx.EVT_SIZE(self, self.make_canvas)
# now put a button on the panel, on top of the wallpaper
sizer = wx.GridBagSizer()
self.entry = wx.TextCtrl(self, -1, value=u"Enter Waybill No.")
sizer.Add(self.entry, (0, 0), (1, 1), wx.EXPAND)
self.Bind(wx.EVT_TEXT_ENTER, self.OnPressEnter, self.entry)
button = wx.Button(self, -1, label="Add or Compare")
sizer.Add(button, (0, 1))
self.Bind(wx.EVT_BUTTON, self.OnButtonClick, button)
self.label = wx.StaticText(self, -1, label=u'This App is used !')
self.label.SetBackgroundColour(wx.WHITE)
self.label.SetForegroundColour(wx.BLUE)
sizer.Add(self.label, (1, 0), (1, 2), wx.EXPAND)
sizer.AddGrowableCol(0)
self.SetSizerAndFit(sizer)
self.SetSizeHints(-1, self.GetSize().y, -1, self.GetSize().y)
self.entry.SetFocus()
self.entry.SetSelection(-1, -1)
self.Show(True)
def make_canvas(self, event=None):
# create the paint canvas
dc = wx.ClientDC(self)
# forms a wall-papered background
# formed from repeating image tiles
brush_bmp = wx.BrushFromBitmap(self.bmp)
dc.SetBrush(brush_bmp)
# draw a rectangle to fill the canvas area
w, h = self.GetClientSize()
dc.DrawRectangle(0, 0, w, h)
def OnButtonClick(self, event):
self.label.SetLabel(self.entry.GetValue() + " You clicked the button !")
self.entry.SetFocus()
self.entry.SetSelection(-1, -1)
on click events
def OnPressEnter(self, event):
self.label.SetLabel(self.entry.GetValue() + " You pressed enter !")
self.entry.SetFocus()
self.entry.SetSelection(-1, -1)