Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3 tkinter askdirectory_Python_Python 3.x_Tkinter - Fatal编程技术网

Python3 tkinter askdirectory

Python3 tkinter askdirectory,python,python-3.x,tkinter,Python,Python 3.x,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")

嗨,我有这个代码:

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\u show\u location1中显示self.save的位置 我试着把self.save放在self.label\u show\u位置1他给我按摩: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)

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

为方便起见,如果您不打算为该函数发送参数,请不要将lambda用作命令参数。提示:如果我不为该函数发送参数,我将删除lambda