同一图形界面:tkinter和wxPython代码对比

一:运行效果

1.tkinter :windows平台运行效果

同一图形界面:tkinter和wxPython代码对比_第1张图片

2.tkinter:linux平台运行效果

同一图形界面:tkinter和wxPython代码对比_第2张图片

3.wxPython运行效果

同一图形界面:tkinter和wxPython代码对比_第3张图片

二:代码

1.tkinter代码

from Tkinter import *
from tkFont import Font
try:
    from ttk import (Button, Scrollbar)
except ImportError:
    pass

class MyFrame(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.root = master
        self.pack(fill=BOTH, expand=True)
        self.font_en = Font(self, size=14)
        self.create_widgets()

    def create_widgets(self):
        self.fm_up = Frame(self)
        self.en = Entry(self.fm_up, font=self.font_en)
        self.en.pack(side=LEFT, expand=True, fill=X, padx=5, pady=5)
        self.loadbutton = Button(self.fm_up, text='Open')
        self.savebutton = Button(self.fm_up, text='Save')
        self.loadbutton.pack(side=LEFT, pady=5)
        self.savebutton.pack(side=LEFT, padx=5)
        self.fm_up.pack(fill=X)

        self.fm_down = Frame(self)
        self.fm_text_scb_ver = Frame(self.fm_down)
        self.text = Text(self.fm_text_scb_ver, width=30, height=15)
        self.scb_ver = Scrollbar(self.fm_text_scb_ver)
        self.text.pack(side=LEFT, fill=BOTH, expand=True, padx=5)
        self.scb_ver.pack(side=RIGHT, fill=Y)
        self.fm_text_scb_ver.pack(fill=BOTH, expand=True)
        self.fm_scb_hor = Frame(self.fm_down)
        self.scb_hor = Scrollbar(self.fm_scb_hor, orient=HORIZONTAL)
        self.scb_hor.pack(fill=X)
        self.fm_scb_hor.pack(fill=X)
        self.text.config(xscrollcommand=self.scb_hor.set,
                         yscrollcommand=self.scb_ver.set)
        self.scb_hor.config(command=self.text.xview)
        self.scb_ver.config(command=self.text.yview)
        self.fm_down.pack(fill=BOTH, expand=True)

if __name__ == "__main__":
    root = Tk()
    root.title('Simple Editor')
    MyFrame(root)
    root.mainloop()

2.wxPython代码:

import wx

class MyFrame(wx.Frame):

    def __init__(self, parent=None, id=-1, title=''):
        wx.Frame.__init__(self, parent, id, title,
                          size=(410, 335))
        self.panel = wx.Panel(self)
        self.bt_load = wx.Button(self.panel, label='Open')
        self.bt_save = wx.Button(self.panel, label='Save')
        self.filename = wx.TextCtrl(self.panel)
        self.contents = wx.TextCtrl(self.panel,
                                    style=wx.TE_MULTILINE | wx.HSCROLL)
        self.hbox = wx.BoxSizer()
        self.hbox.Add(self.filename, proportion=1, flag=wx.EXPAND)
        self.hbox.Add(self.bt_load, flag=wx.LEFT, border=5)
        self.hbox.Add(self.bt_save, flag=wx.LEFT, border=5)

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.hbox, flag=wx.EXPAND | wx.ALL, border=5)
        self.vbox.Add(self.contents, proportion=1,
                      flag=wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT,
                      border=5)
        self.panel.SetSizer(self.vbox)

if __name__ == "__main__":
    app = wx.App()
    MyFrame(None, title='Simple Editor').Show()
    app.MainLoop()



你可能感兴趣的:(python,Tkinter,python,Tkinter,图形,界面,编程)