1.以管理员身份运行
import win32com.shell.shell as shell
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:] + [ASADMIN])
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
sys.exit(0)
2.窗口置顶
self.UI = Tk()
self.UI.wm_attributes('-topmost', 1)
3.设置窗口大小
self.UI = Tk()
self.UI.geometry('650x450')
4.创建按钮
self.text = tkinter.StringVar()
self.text.set("缩小")
btn1 = Button(self.UI, text='开始执行', bd='5', command=self._implementOrder)
btn2 = Button(self.UI, text='保存地址', bd='5', command=self._savePath)
self.btn3 = Button(self.UI, textvariable=self.text, bd='5', command=self._changeSize)
btn1.grid(row=1, column=1)
btn2.grid(row=2, column=1)
self.btn3.grid(row=3, column=1)
5.创建复选窗口
self.CheckVar1 = IntVar(value=self.isOpenZBBL)
self.CheckVar2 = IntVar(value=self.isCloseZBBL)
self.CheckVar3 = IntVar(value=self.isCopyFiles[0])
self.CheckVar4 = IntVar(value=self.isCopyFiles[1])
self.CheckVar5 = IntVar(value=self.isCopyFiles[2])
openZBBL = Checkbutton(self.UI, text="打开xx", variable=self.CheckVar1, onvalue=1, offvalue=0, height=5,
width=20, command=self._checkbutton_OpenZBBL)
closeZBBL = Checkbutton(self.UI, text="关闭xx", variable=self.CheckVar2, onvalue=1, offvalue=0, height=5,
width=20, command=self._checkbutton_CloseZBBL)
copyFile1 = Checkbutton(self.UI, text="拷贝此文件", variable=self.CheckVar3, onvalue=1, offvalue=0, height=5,
width=20, command=self._checkbutton_CopyFile1)
copyFile2 = Checkbutton(self.UI, text="拷贝此文件", variable=self.CheckVar4, onvalue=1, offvalue=0, height=5,
width=20, command=self._checkbutton_CopyFile2)
copyFile3 = Checkbutton(self.UI, text="拷贝此文件", variable=self.CheckVar5, onvalue=1, offvalue=0, height=5,
width=20, command=self._checkbutton_CopyFile3)
openZBBL.grid(row=1, column=2)
closeZBBL.grid(row=2, column=2)
copyFile1.grid(row=1, column=3)
copyFile2.grid(row=3, column=3)
copyFile3.grid(row=5, column=3)
6.创建文本框
rst = [StringVar(self.UI, value=self.GroupSource[0]),
StringVar(self.UI, value=self.GroupSource[1]),
StringVar(self.UI, value=self.GroupSource[2])]
dst = [StringVar(self.UI, value=self.GroupDst[0]),
StringVar(self.UI, value=self.GroupDst[1]),
StringVar(self.UI, value=self.GroupDst[2])]
self.rstpath = [Entry(self.UI, width=30, bd=6, textvariable=rst[0]),
Entry(self.UI, width=30, bd=6, textvariable=rst[1]),
Entry(self.UI, width=30, bd=6, textvariable=rst[2])]
self.dstpath = [Entry(self.UI, width=30, bd=6, textvariable=dst[0]),
Entry(self.UI, width=30, bd=6, textvariable=dst[1]),
Entry(self.UI, width=30, bd=6, textvariable=dst[2])]
for i in range(3):
self.rstpath[i].grid(row=1 + i * 2, column=4)
self.dstpath[i].grid(row=2 + i * 2, column=4)