Python3 tkinter 询问目录

陈帕塔

嗨,我有这个代码:

from tkinter import *
from tkinter import filedialog
from pytube import YouTube

class download_youtube_video:
    def __init__(self):
        self.ydownload4u = Tk()
        self.ydownload4u.title("Youtube download for you")
        self.ydownload4u.geometry("400x400+600+250")

        label_title = Label(self.ydownload4u, text="Youtube Download For You", font="times 25 bold underline")
        label_title.place(x=40, y=10)

        label_link = Label(self.ydownload4u, text="Please enter link of video Youtube:", font="times 15")
        label_link.place(x=35, y=70)

        self.box_link = Entry(self.ydownload4u, width="35")
        self.box_link.place(x=30, y=100)

        label_save = Label(self.ydownload4u, text="Please select where save file:", font="times 15")
        label_save.place(x=35, y=150)


        self.save_location = Button(self.ydownload4u, text="save as", command=lambda :self.save_as())
        self.save_location.place(x=260, y=135)
        self.save_location.config(height = 3, width = 10)

        self.label_show_loction = Label(self.ydownload4u, text="You are save file here: ")
        self.label_show_loction.place(x=35, y=220)

        self.label_show_loction1 = Label(self.ydownload4u, text= lambda :self.save_as())
        self.label_show_loction1.place(x=175, y=220)



        self.ydownload4u.mainloop()

    def save_as(self):
        self.save = filedialog.askdirectory()

我想在 self.label_show_loction1 中显示 self.save 的位置我试着把 self.save 放在 self.label_show_loction1 他给我按摩:140544723958912 请帮帮我

字节码

只需从 tk 创建一个字符串变量并将其作为文本变量添加到您的标签、按钮或任何类型的组件中,例如:

self.loc1 = tk.StringVar(value="")
self.label_show_loction1 = Label(self.ydownload4u, textvariable=self.loc1)

要更改变量值,您可以执行以下操作:

tk.Button(self.frameName, text="save as", command=self.save_as)

def save_as(self):
    save = filedialog.askdirectory()
    self.loc1.set(save)

当您单击按钮时,变量将被更新并显示在您放置的位置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章