我创建了单击并运行python / open文件的按钮。
import subprocess
import sys
import os
import tkinter
from tkinter import messagebox
top=tkinter.Tk()
class object_1:
def __init__(self, G, M, L, R):
## G is the .py script
## M is the manual
## L is the location
## R is the botton column
self.G = G
self.M = M
self.L = L
self.R = R
def script(self):
## Change the working folder
os.chdir(self.L)
## Run the .py
os.system(self.G)
## Create button for running .py
def script_run(self):
script_obj = tkinter.Button(text = self.G, command = lambda:self.script())
script_obj.grid(row = self.R, column = 0)
def manual(self):
## Change the working folder
os.chdir(self.L)
## Open the .pptx manual
subprocess.call(('cmd', '/C', 'start', '', lambda:self.M))
## Create button for opening .pptx manual
def manual_run(self):
manual_obj = tkinter.Button(text=self.M,command= lambda:self.manual(), bg='grey')
manual_obj.grid(row = self.R, column = 1)
def run_all(self):
self.script_run()
self.manual_run()
# These three should be combined together
script_value = ['Script1',
'Script2']
manual_value = ['Script1_PPT.pptx',
'Script2_PPT.pptx']
location_value = ['C:\Python34\Location1',
'C:\Python34\Location2']
# loop through three locations, every scripts has its own location, even if they are the same
for i in range(2):
GUI_Class = object_1(script_value[i], manual_value[i], location_value[i], i)
GUI_Class.run_all()
谢谢!