====== Hello world in Wxpython ====== Autore: **//Fabio Di Matteo//** \\ Ultima revisione: **// 03/01/2019 - 19:34 //** // // **hello.py** #!/usr/bin/env python3 import wx from wx import xrc class MyApp(wx.App): def OnInit(self): self.res = xrc.XmlResource('gui.xrc') self.init_frame() return True def init_frame(self): self.frame = self.res.LoadFrame(None, 'mainFrame') self.panel = xrc.XRCCTRL(self.frame, 'panel') self.text1 = xrc.XRCCTRL(self.panel, 'text1') self.text2 = xrc.XRCCTRL(self.panel, 'text2') self.text1.SetValue("Ciao mondo!") self.frame.Bind(wx.EVT_BUTTON, self.OnSubmit, id=xrc.XRCID('button')) self.frame.Show() def OnSubmit(self, evt): wx.MessageBox('Your name is %s %s!' % (self.text1.GetValue(), self.text2.GetValue()), 'Feedback') if __name__ == '__main__': app = MyApp(False) app.MainLoop() **gui.xrc** My Frame 2 3 5 5 0,0 ===== Gestire i menu da file xrc ===== La procedura รจ un po' diversa ma assomiglia a quella dei widgets: #Getting menu self.menubar = self.frame.GetMenuBar() self.mnuItemExit = self.menubar.FindItemById(xrc.XRCID('mnuItemExit')) self.mnuItemNewProfile = self.menubar.FindItemById(xrc.XRCID('mnuItemNewProfile')) #Bind event Menu self.frame.Bind(wx.EVT_MENU, self.quit, self.mnuItemExit) self.frame.Bind(wx.EVT_MENU, self.openProfiles, self.mnuItemNewProfile) ===== Freezare la nostra app ===== Usando cx_freeze possiamo usare il seguente script. **make.py** import sys from cx_Freeze import setup, Executable # Dependencies are automatically detected, but it might need fine tuning. build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]} # GUI applications require a different base on Windows (the default is for a # console application). base = None if sys.platform == "win32": base = "Win32GUI" setup( name = "guifoo", version = "0.1", description = "My GUI application!", options = {"build_exe": build_exe_options}, executables = [Executable("hello.py", base=base)])