python - Why can't the contents in these three entries change simultaneously? -


firstly let's @ program:

def entry_simutaneously_change():         tkinter import *          root=tk()         text_in_entry.set(0)          entry(root, width=30, textvariable= text_in_entry).pack()         entry(root, width=30, textvariable= text_in_entry).pack()         entry(root, width=30, textvariable= text_in_entry).pack()          root.mainloop() 

the contents in these 3 entries can change simultaneously. if change value of of them, other 2 change @ same time. however, following program:

def entry_simutaneously_change():         tkinter import *          root=tk()         text_in_entry_list=[intvar() in range(0,3)]         text_in_entry_list[0].set(0)         text_in_entry_list[1].set(text_in_entry_list[0].get() ** 2)         text_in_entry_list[2].set(text_in_entry_list[0].get() ** 3)          entry(root, width=30, textvariable= text_in_entry_list[0]).pack()         entry(root, width=30, textvariable= text_in_entry_list[1]).pack()         entry(root, width=30, textvariable= text_in_entry_list[2]).pack()          root.mainloop() 

when change content in first entry, contents in other 2 not change. why?

in first program, have 1 source of data, text_in_entry. consider 1 box you're placing single value that's read each entry.

in second program, have 3 sources of data, text_in_entry[0, 1, , 2]. lines set initial value called once. it's have 3 boxes data placed; set initial values, @ value inside first, there no association between three.

if achieve same type of result first program (when 3 entries update simultaneously) need bind on event. note tkinker not have on-change style event there various hacks, bind focusout event. general idea ask function called when change occurs entry (binding callback). inside function update other 2 values based on new value in entry changed.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -