首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python3 tkinter命令目录

Python3 tkinter命令目录
EN

Stack Overflow用户
提问于 2020-07-01 22:45:17
回答 1查看 150关注 0票数 0

嗨,我有个密码:

代码语言:javascript
复制
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,请帮我

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-01 22:55:03

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

代码语言:javascript
复制
self.loc1 = tk.StringVar(value="")
self.label_show_loction1 = Label(self.ydownload4u, textvariable=self.loc1)

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

代码语言:javascript
复制
tk.Button(self.frameName, text="save as", command=self.save_as)

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62686393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档