将tkinter按钮参数保存到文件?
我正在尝试弄清楚如何使用Pickle保存TKINTER按钮的参数。
到目前为止,我正在考虑将所有参数放在字符串中,保存字符串,然后从字符串中定义按钮的参数?
它根本不起作用,但是看起来像这样:
def tapisone_on():
tapisonevar = tkinter.StringVar(win,text= "TAPIS #1\nACTIF", bg="green", fg="black", command = tapisone_off)
def tapisone_off():
tapisonevar = tkinter.StringVar(win,text= "TAPIS #1", bg="grey", fg="red", command = tapisone_on)
tapisonevar = tkinter.StringVar(win,'frameripple, text ="TAPIS #1", font=44, bg="grey", fg="red", command = tapisone_on')
tapisone = tkinter.Button(tapisonevar)
tapisone.place(relx=0.055, rely=0.105, relwidth = 0.2, relheight=0.4, anchor= "nw")
您是否知道该怎么做?
我需要能够从文件上按下面板上按下的按钮。
I am trying to figure out how to save the parameters of a tkinter button by using pickle.
So far I'm thinking of putting all parameters within a string, saving the string and then defining the button's parameters from the string ?
It doesn't work at all, but it kinda looks like this:
def tapisone_on():
tapisonevar = tkinter.StringVar(win,text= "TAPIS #1\nACTIF", bg="green", fg="black", command = tapisone_off)
def tapisone_off():
tapisonevar = tkinter.StringVar(win,text= "TAPIS #1", bg="grey", fg="red", command = tapisone_on)
tapisonevar = tkinter.StringVar(win,'frameripple, text ="TAPIS #1", font=44, bg="grey", fg="red", command = tapisone_on')
tapisone = tkinter.Button(tapisonevar)
tapisone.place(relx=0.055, rely=0.105, relwidth = 0.2, relheight=0.4, anchor= "nw")
Do You have any idea how something like that can be done?
I need to be able to load what buttons where pressed down on a panel from a file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是如何使用
泡菜
将按钮
选项存储在文件中的示例,然后稍后将其读取以实际创建相应的小部件。它为每个按钮选项分配一个名称,并在字典中为与该名称相关的字典创建一个条目。每组选项本身都由嵌套词典表示。这使得在创建按钮
s时可以轻松指定它们。请注意,可以扩展此基本想法,还可以存储有关每个按钮的其他信息,例如应该放置在何处。
Here's an example of how to use
pickle
to storeButton
options in a file and read them back later to use to actually create the corresponding widget. It assigns a name to each group of button options and creates an entry in a dictionary for them associated with that name. Each group of options is itself represented by a nested dictionary. This makes it easy to specify them when creating theButton
s later on.Note that this basic idea could be extended to also store other information about each button, such as where it should be placed.