需要使用到的文件wxapp.py, read_file.py, setup.py
复制代码 代码如下:
import wx
import os
import sys
import read_file
class Frame(wx.Frame):
def init(self):
wx.Frame.init(self, parent=None, title='Hello from cx_Freeze')
panel = wx.Panel(self)
closeMeButton = wx.Button(panel, -1, 'Close Me')
wx.EVT_BUTTON(self, closeMeButton.GetId(), self.OnCloseMe)
wx.EVT_CLOSE(self, self.OnCloseWindow)
pushMeButton = wx.Button(panel, -1, 'Push Me')
wx.EVT_BUTTON(self, pushMeButton.GetId(), self.OnPushMe)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(closeMeButton, flag=wx.ALL, border=20)
sizer.Add(pushMeButton, flag=wx.ALL, border=20)
panel.SetSizer(sizer)
topSizer = wx.BoxSizer(wx.VERTICAL)
topSizer.Add(panel, flag=wx.ALL | wx.EXPAND)
topSizer.Fit(self)
def OnCloseMe(self, event):
obj = read_file.PrintContent()
if getattr(sys, 'frozen', None):
path = os.path.dirname(sys.executable)
else:
path = os.path.dirname(__file__)
path = os.path.join(path, "read_file.py")
obj.show_content(path)
def OnPushMe(self, event):
wx.MessageBox('I was pushed!', 'Informational message')
def OnCloseWindow(self, event):
self.Destroy()
class App(wx.App):
def OnInit(self):
frame = Frame()
frame.Show(True)
self.SetTopWindow(frame)
return True
app = App(1)
app.MainLoop()
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8