Ich lerne ui Python und Wxpython für UI-Entwicklung ausprobieren (nicht UI exp entweder). Ich konnte einen Rahmen mit einem Panel, einer Schaltfläche und einem Texteingabefeld erstellen. Ich möchte alle diese in die Mitte des Bildschirms bringen, wo sie richtig aussehen, so dass ich den Rest der Funktionalität implementieren kann. zur Zeit überlappen siemöchten Sie ein Textfeld und Schaltfläche und statisches Feld in der Mitte des Bildschirms auf ein Bild mit wxpython hinzufügen? helfen Sie mir, nicht zu überlappen und Platzierung
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)