1. 程式人生 > 實用技巧 >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):
    #這個類實現具體的事件處理回撥函式。介面生成程式碼在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()