[[oktatas:programozás:python:wxpython_gui|< wxPython GUI]]
====== wxPython Sávok ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2020, 2021
* [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Státuszsor =====
class MainFrame(wx.Frame):
...
def initUI(self):
self.statusBar = self.CreateStatusBar(2)
self.statusBar.SetStatusText('első', 0)
self.statusBar.SetStatusText('második', 1)
===== Eszköztár =====
class MainFrame(wx.Frame):
def __init__(self, parent):
super(MainFrame, self).__init__(parent)
self.InitUI()
self.InitLayout()
def InitUI(self):
self.SetSize((800,600))
self.textCtrl1 = wx.TextCtrl(self)
self.button1 = wx.Button(self, label='Mehet')
self.button1.Bind(wx.EVT_BUTTON, self.onClickButton1)
self.toolBar = self.CreateToolBar(wx.TB_HORIZONTAL, wx.ID_ANY)
self.backTool = self.toolBar.AddTool(1001, 'Vissza', wx.Bitmap('back.png'))
self.Bind(wx.EVT_TOOL, self.onClickBackTool, self.backTool)
self.toolBar.Realize()
def InitLayout(self):
rootBox = wx.BoxSizer(wx.VERTICAL)
rootBox.Add(textCtrl1)
rootBox.Add(button1)
self.SetSizer(rootBox)
def onClickButton1(self, event):
self.browser.LoadURL(self.address.GetValue())
def onClickBackTool(self, event):
self.browser.GoBack()
===== Menü =====
import wx
class FoMenu(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, pos=(150,150), size=(350, 200))
menusav = wx.MenuBar()
fajl = wx.Menu()
szerkesztes = wx.Menu()
segitseg = wx.Menu()
fajl.Append(101, '&Megnyitás', 'Új dokumentum megnyitása')
fajl.Append(102, '&Mentés', 'Dokumentum mentése')
fajl.AppendSeparator()
quit = wx.MenuItem(fajl, 105, '&Kilépés\tCtrl+Q', 'Kilépés a programból')
fajl.Append(quit)
menusav.Append(fajl, '&Fájl')
menusav.Append(szerkesztes, 'S&zerkesztés')
menusav.Append(segitseg, '&Segítség')
self.SetMenuBar(menusav)
self.CreateStatusBar()
class FoApp(wx.App):
def OnInit(self):
frame = FoMenu(None, 'Progim')
frame.Show(True)
return True
app = FoApp(0)
app.MainLoop()
===== Popup menü =====
import wx
class PopupMenu(wx.Menu):
def __init__(self, parent):
super(PopupMenu, self).__init__()
self.parent = parent
item1 = wx.MenuItem(self, wx.ID_ANY, 'Első')
item2 = wx.MenuItem(self, wx.ID_ANY, 'Második')
self.Append(item1)
self.Append(item2)
self.Bind(wx.EVT_MENU, self.on_menu_item1, item1)
self.Bind(wx.EVT_MENU, self.on_menu_item2, item2)
def on_menu_item1(self, event):
print("Első")
def on_menu_item2(self, event):
print("Második")
class MainFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.init_frame()
self.set_layout()
def init_frame(self):
#komponensek beállítása
self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down)
self.SetTitle("Program01")
self.Centre()
def set_layout(self):
#layout
main_box = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(main_box)
self.Layout()
def on_right_down(self, event):
self.PopupMenu(PopupMenu(self), event.GetPosition())
class SimpleApp(wx.App):
def OnInit(self):
self.frame = MainFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = SimpleApp()
app.MainLoop()
===== Forrás =====
* [[https://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/ |https://www.blog.pythonlibrary.org/]] (2020)
* [[https://brucey.net/programming/blitz/tutorials/prog/en/menustoolbars.html]] (2020)
* https://www.tutorialspoint.com/wxpython/wx_toolbar_class.htm (2020)