[英]Using Variables with a tkinter button
I am making a program which a user can create his own tkinter buttons. 我正在制作一个程序,用户可以创建自己的tkinter按钮。 However I have a problem with the custom name.
但是我对自定义名称有疑问。 It creates a name by storing it in a variable however it completely ignores the variable even when it is a direct variable.
它通过将名称存储在变量中来创建名称,但是即使它是直接变量,它也会完全忽略该变量。 Eg:
variable = "TEXT HERE"
例如:
variable = "TEXT HERE"
Folder = open(fold2, "r")
Title = Folder.readline(1)
FolderBNam = Button(self, anchor=tk.W, text=Title, command= lambda: self.controller.show_frame(FoldButton1))
FolderBNam.place(height=55, width=75,x=25,y=100)
Folder.close
I have searched for answers of course and even tried to use Lamdba which didn't go so good. 我当然已经在寻找答案,甚至尝试使用Lamdba,效果并不理想。
The only immediate problem I see is file.readline
shouldn't be called with an argument. 我看到的唯一直接的问题是
file.readline
不应使用参数调用。 That should be giving you one character rather than one line (equivalent to Folder.read(1)
. Check my edited code below, also edited to look more like Python: 那应该是给您一个字符而不是一行(相当于
Folder.read(1)
。请检查下面我编辑的代码,并对其进行编辑,使其看起来更像是Python:
import tkinter as tk
from tkinter import ttk
with open(fold2) as f:
title = f.readline() # no argument
f_bnam = ttk.Button(self, anchor=tk.W, text=title, command=...)
f_bnam.place(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.