因此,我试图将变量“核对”宣布为全球变量,因为我得到了以下问题:
File "C:Python27ProjectsAutomatic Installerautoinstall.py", line 11, in installFunc
if checks[0] == 1:
NameError: global name checks is not defined
这里的代码, 我试图在程序的主体和安装功能中添加全局检查。 我是否应该添加另一个位置/ 其它方式来表示检查应该包含程序的信息?
import urllib
import subprocess
from Tkinter import *
global checks
def installFunc():
global checks
subprocess.call("md c:MGInstall", shell=True)
subprocess.call (u"net use w: \it01files")
if checks[0] == 1:
subprocess.call(u"w:\software\snagitup.exe")
if checks[1] == 1:
subprocess.call(u"w:\software\camtasia.exe")
if checks[2] == 1:
urllib.urlretrieve(u"SUPERLONGURLLOLOLOL", u"c:\MGinstall\gotomeeting.exe")
subprocess.call (u"c:\MGinstall\gotomeeting.exe")
urllib.urlretrieve(u"http://ninite.com/.net-7zip-air-chrome-cutepdf-dropbox-essentials-firefox-flash-flashie-java-klitecodecs-quicktime-reader-safari-shockwave-silverlight-vlc/ninite.exe", u"c:\MGinstall\MGinstall.exe")
subprocess.call (u"c:\MGinstall\MGinstall.exe")
subprocess.call (u"w:\printers\installer\printer.exe")
app = Tk()
w = Label(app, text="CompanyName IT Automatic Installer")
w.pack()
text = ["Snagit", "Camtasia", "GotoMeeting"]
variables = []
for name in text:
variables.append(IntVar())
Checkbutton(text=name, variable=variables[-1]).pack()
b = Button(text="OK", command=installFunc)
b.pack()
app.mainloop()
checks = [variable.get() for variable in variables]