大家好,本文将围绕用python写的好玩的小程序展开说明,如何用python做小软件是一个很多人都想弄明白的事情,想搞清楚如何制作python小软件需要先了解以下几个事情。
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os, sys
from tkinter import *
from tkinter.font import Font
from tkinter.ttk import *
#Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
from tkinter.messagebox import *
#Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
#import tkinter.filedialog as tkFileDialog
#import tkinter.simpledialog as tkSimpleDialog #askstring()
class Application_ui(Frame):
#这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.title('Form1')
self.master.geometry("209x472+1500+150")
self.createWidgets()
def createWidgets(self):
self.top = self.winfo_toplevel()
self.style = Style()
self.Command1Var = StringVar(value='python')
self.style.configure('TCommand1.TButton', font=('宋体',9))
self.Command1 = Button(self.top, text='Command1', textvariable=self.Command1Var, command=self.Command1_Cmd, style='TCommand1.TButton')
self.Command1.setText = lambda x: self.Command1Var.set(x)
self.Command1.text = lambda : self.Command1Var.get()
self.Command1.place(relx=0.096, rely=0.085, relwidth=0.818, relheight=0.108)
self.Command2Var = StringVar(value='auto.js')
self.style.configure('TCommand2.TButton', font=('宋体',9))
self.Command2 = Button(self.top, text='Command2', textvariable=self.Command2Var, command=self.Command2_Cmd, style='TCommand2.TButton')
self.Command2.setText = lambda x: self.Command2Var.set(x)
self.Command2.text = lambda : self.Command2Var.get()
self.Command2.place(relx=0.096, rely=0.233, relwidth=0.818, relheight=0.15)
self.Command3Var = StringVar(value='下载总位置')
self.style.configure('TCommand3.TButton', font=('宋体',9))
self.Command3 = Button(self.top, text='Command3', textvariable=self.Command3Var, command=self.Command3_Cmd, style='TCommand3.TButton')
self.Command3.setText = lambda x: self.Command3Var.set(x)
self.Command3.text = lambda : self.Command3Var.get()
self.Command3.place(relx=0.096, rely=0.445, relwidth=0.77, relheight=0.15)
self.Command4Var = StringVar(value='源码收集')
self.style.configure('TCommand4.TButton', font=('宋体',9))
self.Command4 = Button(self.top, text='Command4', textvariable=self.Command4Var, command=self.Command4_Cmd, style='TCommand4.TButton')
self.Command4.setText = lambda x: self.Command4Var.set(x)
self.Command4.text = lambda : self.Command4Var.get()
self.Command4.place(relx=0.096, rely=0.657, relwidth=0.77, relheight=0.108)
self.Command5Var = StringVar(value='工作区')
self.style.configure('TCommand5.TButton', font=('宋体',9))
self.Command5 = Button(self.top, text='Command5', textvariable=self.Command5Var, command=self.Command5_Cmd, style='TCommand5.TButton')
self.Command5.setText = lambda x: self.Command5Var.set(x)
self.Command5.text = lambda : self.Command5Var.get()
self.Command5.place(relx=0.096, rely=0.826, relwidth=0.77, relheight=0.108)
class Application(Application_ui):
#这个类实现具体的事件处理回调函数70个python练手项目列表。界面生成代码在Application_ui中。
def __init__(self, master=None):
Application_ui.__init__(self, master)
def Command1_Cmd(self, event=None):
os.startfile("F:\源码收集\python")
self.quit()
def Command2_Cmd(self, event=None):
os.startfile("F:\源码收集\\aotu.js")
self.quit()
def Command3_Cmd(self, event=None):
os.startfile("D:\下载总位置")
self.quit()
def Command4_Cmd(self, event=None):
os.startfile("F:\源码收集")
self.quit()
def Command5_Cmd(self, event=None):
os.startfile("G:")
self.quit()
if __name__ == "__main__":
top = Tk()
Application(top).mainloop()