2.x版本下名为Tkinter,3.X下名为tkinter,注意首字母大小写不一样
Import tkinter as tk
Root = tk.Tk()
Tk.mainloop()
布局三种方法,pack grid place,同级只能用一种方法,可以用Frame破解规定
Menubar = tk.Menu(root)
For i in ls:
Menubar.add_command(label=’xxx’,command=aaa’
Root[‘menu’]=menubar
子目录的话,再附加
Fmenu = tk.Menu(menubar)
Menubar.add_cascade(label=’文件’,menu=fmenu)
更改表现,表现更好看些
from tkinter import *
from tkinter.ttk import *
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
if __name__ == '__main__':
root = Tk()
root.iconbitmap('logo.ico')
root.title('一键删除重复文件')
menu = Menu(root)
menu.add_command(label='about',command=about)
root['menu'] = menu
input_dir = StringVar()
Entry(root,textvariable=input_dir,width=60).grid(row=0,column=1,sticky=W)
fra_ext = Frame(root)
ext_var=IntVar()
for ext in exts:
radiobutton = Radiobutton(fra_ext,text=ext,variable=ext_var,value=exts.index(ext))
radiobutton.pack(side=LEFT)
frame_del = Frame()
#text_del = Text(frame_del,bg='#ccffcc',width=50,height=5)
text_del = Text(frame_del,width=60,height=5)
sb=Scrollbar(frame_del,orient=VERTICAL)
sb.configure(command=text_del.yview)
sb.pack(side=RIGHT,fill=Y)
text_del.config(yscrollcommand=sb.set)
text_del.pack(side=LEFT, fill=BOTH, expand=1)
Label(root,text='目录').grid(row=0)
Button(root,text='1.选择\n整理目录',command=askdir).grid(row=0,column=2)
Label(root,text='文件后缀名').grid(row=1)
Label(root,text='<--2.选后缀名').grid(row=1,column=2)
fra_ext.grid(row=1,column=1,sticky=W)
Button(root,text='3.查找\n重复文件',command=search).grid(row=2,column=2)
Label(text='找到以下\n重复文件').grid(row=4,column=0)
frame_del.grid(row=4,column=1,sticky=W)
Button(root,text='4.删除\n重复文件',command=delete).grid(row=4,column=2)
status = StringVar()
status.set('状态:请选择目录')
Label(root,textvariable=status).grid(row=5,column=1,sticky=W)
root.mainloop()
界面如下
from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import askdirectory
from tkinter import messagebox
if __name__ == '__main__':
root = Tk()
root.title(title)
menu = Menu(root)
menu.add_command(label='About', command=about)
root['menu'] = menu
Label(root, text='图片目录:').grid(sticky=W, row=0, column=0, pady=padY)
pic_dir = StringVar()
Entry(root, textvariable=pic_dir, width=30).grid(row=0, column=1, sticky=W)
Button(
root,
text=' 选择 ',
command=askInputDir).grid(
row=0,
column=2,
padx=padX)
sub_dir = IntVar()
sub_dir.set(1)
Checkbutton(
root,
variable=sub_dir,
text='子目录亦生成PDF').grid(
row=1,
column=1,
sticky=W)
Label(root, text='输出PDF位置:').grid(row=2, column=0, pady=padY)
output_dir = StringVar()
Entry(root, textvariable=output_dir, width=30).grid(row=2, column=1,
sticky=W)
Button(root, text=' 更改 ', command=askOutputDir).grid(row=2,
column=2)
Button(root, text=' 生成PDF ', command=do).grid(row=3, column=1,
padx=padX, pady=padY)
status = StringVar()
status.set('状态:请选择目录')
Label(root, textvariable=status).grid(row=4, column=1, sticky=W)
root.mainloop()
界面如下