#!/usr/bin/env python #-*- coding:utf-8 -*- import os, sys try: from tkinter import * except ImportError: #Python 2.x PythonVersion = 2 from Tkinter import * from tkFont import Font from ttk import * #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel from tkMessageBox import * #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python') #import tkFileDialog #import tkSimpleDialog else: #Python 3.x PythonVersion = 3 from tkinter.font import Font from tkinter.ttk import * from tkinter.messagebox import * class Application_ui(Frame): #这个类仅实现界面生成功能,具体事件处理代码在子类Application中。 def __init__(self, master=None): Frame.__init__(self, master) self.master.title('Form1') self.master.geometry('457x271') self.createWidgets() def createWidgets(self): self.top = self.winfo_toplevel() self.style = Style() self.Frame1 = LabelFrame(self.top, text='Frame1') self.Frame1.place(relx=0.018, rely=0.03, relwidth=0.93, relheight=0.889) self.Command1 = Button(self.Frame1, text='Command1', command=self.Command1_Cmd) self.Command1.place(relx=0.659, rely=0.797, relwidth=0.285, relheight=0.137) self.Command2 = Button(self.Frame1, text='Command2', command=self.Command2_Cmd) self.Command2.place(relx=0.32, rely=0.797, relwidth=0.322, relheight=0.137) class Application(Application_ui): #这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。 def __init__(self, master=None): Application_ui.__init__(self, master) def Command1_Cmd(self, event=None): #按钮1触发事件! pass def Command2_Cmd(self, event=None): #按钮2触发事件! pass if __name__ == "__main__": top = Tk() Application(top).mainloop() try: top.destroy() except: pass
Python-图形界面封装
猜你喜欢
转载自www.cnblogs.com/LyShark/p/9186212.html
今日推荐
周排行