element
实际上只是一个 object
,它的值是属性和函数的列表。
类似这样:
{
name: "..."
href: "..."
addEventListener: (...) => ...
}
当您使用解构赋值时,您将孤立地获取这些属性之一。
像这样:
let object = {
name: "..."
href: "..."
addEventListener: (...) => ...
}
let name = object.name
所以当你修改 name
时,没有任何反应。
,
那是因为参数解构的工作原理。当您使用 from tkinter import *
from tkinter.ttk import Combobox
def add():
dict1[entrybox.get()] = {'name_company': entrybox1.get(),'country_company': entrybox2.get()}
print(dict1)
dict1 = {"": {"name_company": 0,"country_company" : 0,},"Company1": {"name_company": "Company1 LTD","country_company": "Germany"}}
window =Tk()
var1=StringVar()
entrybox = Entry(window) #adding main key ("Company1") as an example
entrybox.pack()
entrybox1 = Entry(window) #adding value of sub-key ("name_company")
entrybox1.pack()
entrybox2 = Entry(window) #adding value of sub-key ("country_company")
entrybox2.pack()
combo = Combobox(window,value=list(dict1.keys()),textvariable=dict1[var1.get()])
combo.pack()
button = Button(window,text="Add",command=add)
button.pack()
语法时,它实际上是以下内容的语法糖:
({ name }) => expr
因此,当您执行 (_obj) => {
let name = _obj.name;
delete _obj; // imagine you lose access to the `_obj` variable
return expr;
};
时,您正在更改范围的参数变量,而不是实际的 name = value
字段。
本文链接:https://www.f2er.com/4187.html