下载
- win,mac 直接 pip install wxPython
- linux 在这里下载后在 pip install该文件(含后缀)cp27 代表python2.7 cp36代表python3.6 ,这里我尝试过pip安装,但是会出错。用pycharm查找安装也不行。
这里要注意pip是python2还是python3的,楼主pip是python2的,pip3是python3
wxPython相关软件
- wxWidgets
- wxFormBuilder
有一些软件做出来的代码比较旧,仍然需要替换和修改。
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx, os
###########################################################################
## Class MyFrame2
###########################################################################
class MyFrame2(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u'hengge-Data Wrangling', pos=wx.DefaultPosition,
size=wx.Size(1280, 720), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
bSizer2 = wx.BoxSizer(wx.VERTICAL)
self.m_button1 = wx.Button(self, wx.ID_ANY, u"Python file", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_button1, 0, wx.ALL | wx.EXPAND, 5)
self.Bind(wx.EVT_BUTTON, self.OnClick1, self.m_button1) #绑定事件
self.m_button2 = wx.Button(self, wx.ID_ANY, u"CSV file", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_button2, 0, wx.ALL | wx.EXPAND, 5)
self.Bind(wx.EVT_BUTTON, self.OnClick2, self.m_button2)
self.m_button3 = wx.Button(self, wx.ID_ANY, u"JSON file", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_button3, 0, wx.ALL | wx.EXPAND, 5)
self.Bind(wx.EVT_BUTTON, self.OnClick3, self.m_button3)
self.m_button4 = wx.Button(self, wx.ID_ANY, u"HTML file", wx.DefaultPosition, wx.DefaultSize, 0)
bSizer2.Add(self.m_button4, 0, wx.ALL | wx.EXPAND, 5)
self.Bind(wx.EVT_BUTTON, self.OnClick4, self.m_button4)
self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, size=wx.Size(2000, 2000),
style=wx.TE_MULTILINE)
bSizer2.Add(self.m_textCtrl1, 0, wx.ALL, 5)
self.SetSizer(bSizer2)
self.Layout()
self.Centre(wx.BOTH)
self.Show()
def OnClick1(self, e):
wildcard = "python files (*.py)|*.py" #过滤不是py后缀的文件
dlg = wx.FileDialog(self, "Choose a file", os.getcwd().decode('utf-8'), "", wildcard, wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
f = open(dlg.GetPath(), 'r')
with f:
data = f.read()
self.m_textCtrl1.SetValue(data)
dlg.Destroy()
def OnClick2(self, e):
wildcard = "CSV files (*.csv)|*.csv"
dlg = wx.FileDialog(self, "Choose a file", os.getcwd().decode('utf-8'), "", wildcard, wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
f = open(dlg.GetPath(), 'r')
with f:
data = f.read()
self.m_textCtrl1.SetValue(data)
dlg.Destroy()
def OnClick3(self, e):
wildcard = 'Json files(*.json)|*.json'
dlg = wx.FileDialog(self, "Choose a file", os.getcwd().decode('utf-8'), "", wildcard, wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
f = open(dlg.GetPath(), 'r')
with f:
data = f.read()
self.m_textCtrl1.SetValue(data)
dlg.Destroy()
def OnClick4(self, e):
wildcard = 'html files(*.html)|*.html'
dlg = wx.FileDialog(self, "Choose a file", os.getcwd().decode('utf-8'), "", wildcard, wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
f = open(dlg.GetPath(), 'r')
with f:
data = f.read()
self.m_textCtrl1.SetValue(data)
dlg.Destroy()
app = wx.App()
MyFrame2(None)
app.MainLoop()
这里要注意decode和encode和区别
decode的作用是将其他编码的字符串转换成unicode编码
encode的作用是将unicode编码转换成其他编码的字符串
效果如下