用python写的好玩的小程序,如何用python做小软件

本文介绍了如何使用Python和Tkinter库创建一个包含多个命令按钮的应用程序,每个按钮触发不同的文件操作,如打开源码目录或下载位置。
摘要由CSDN通过智能技术生成

大家好,本文将围绕用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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值