[Python] 纯文本查看 复制代码
import os, sys
from tkinter import *
from tkinter.font import Font
from tkinter.ttk import *
from tkinter.messagebox import *
from tkinter.filedialog import askdirectory
class Application_ui(Frame):
#这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
def __init__(self, master=None):
Frame.__init__(self, master)
self.master.title('视频下载工具')
self.master.geometry('363x239+543+330')
self.createWidgets()
def createWidgets(self):
self.top = self.winfo_toplevel()
self.style = Style()
self.Label1Var = StringVar(value='视频地址:')
self.style.configure('TLabel1.TLabel', anchor='center', font=('Microsoft YaHei UI',9))
self.Label1 = Label(self.top, text='视频地址:', textvariable=self.Label1Var, style='TLabel1.TLabel')
self.Label1.setText = lambda x: self.Label1Var.set(x)
self.Label1.text = lambda : self.Label1Var.get()
self.Label1.place(relx=0.11, rely=0.167, relwidth=0.179, relheight=0.105)
global url
self.Text1Var = StringVar()
self.Text1 = Entry(self.top, textvariable=self.Text1Var, font=('Microsoft YaHei UI',9))
self.Text1.setText = lambda x: self.Text1Var.set(x)
url = lambda : self.Text1Var.get()
self.Text1.place(relx=0.309, rely=0.167, relwidth=0.554, relheight=0.105)
self.Label2Var = StringVar(value='视频保存地址:')
self.style.configure('TLabel2.TLabel', anchor='w', font=('Microsoft YaHei UI',9))
self.Label2 = Label(self.top, text='视频保存地址:', textvariable=self.Label2Var, style='TLabel2.TLabel')
self.Label2.setText = lambda x: self.Label2Var.set(x)
self.Label2.text = lambda : self.Label2Var.get()
self.Label2.place(relx=0.066, rely=0.469, relwidth=0.245, relheight=0.105)
global location
self.Text2Var = StringVar()
self.Text2 = Entry(self.top, textvariable=path, font=('Microsoft YaHei UI',9))
self.Text2.setText = lambda x: self.Text2Var.set(x)
location = lambda : self.Text2Var.get()
self.Text2.place(relx=0.331, rely=0.469, relwidth=0.399, relheight=0.105)
self.Command1Var = StringVar(value='浏览')
self.style.configure('TCommand1.TButton', font=('Microsoft YaHei UI',9))
self.Command1 = Button(self.top, text='浏览', 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.771, rely=0.469, relwidth=0.135, relheight=0.105)
self.Command2Var = StringVar(value='下载')
self.style.configure('TCommand2.TButton', font=('Microsoft YaHei UI',9))
self.Command2 = Button(self.top, text='下载', 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.397, rely=0.736, relwidth=0.201, relheight=0.172)
class Application(Application_ui):
#这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。
def __init__(self, master=None):
Application_ui.__init__(self, master)
def Command1_Cmd(self, event=None):
path_ = askdirectory()
path.set(path_)
def Command2_Cmd(self, event=None):
a = location()
print(a)
b = url()
print(b)
if __name__ == "__main__":
top = Tk()
path = StringVar()
Application(top).mainloop()