고유 변수가있는 ttk.Comboboxes를 여러 개 (이 예제에서는 2 개) 사용하려고합니다. 개별 변수를 선택하도록 허용하지 않고 상자가 선택 항목을 동기화합니다.Python 3.x tkinter comboboxes syncing [ 'variables']
list.py (변수)
class object():
def __init__(self, name):
self.name = name
self.list = ['a','b','c']
main.py (프로그램) :
나는 변수를 저장하는 주요 파일 가져 오기를 사용하고
from tkinter import *
from tkinter import ttk
import list
root = Tk()
aList = list.object('aName')
bList = list.object('bName')
aVariable = aList.list
aCombobox = ttk.Combobox(root, textvariable=aVariable)
aCombobox['values'] = aList.list
aCombobox.grid()
bVariable = bList.list
bCombobox = ttk.Combobox(root, textvariable=bList.list)
bCombobox['values'] = bList.list
bCombobox.grid()
root.mainloop()
변수를 (모듈/클래스로) 가져오고 각각을 초기화합니다 (aList 및 bList) d 두 개의 개별 객체를 만듭니다. 각 Combobox는 의 텍스트 변수을 가지고 있으며 생성 된 개체에서 [valuse]를 생성합니다. 그러나 이것은 작동하지 않습니다 - 그들은 동기화를 유지합니다. A와 (
list.py (위와 같은 수입)
main.py :
나는 그것이 CLI 응용 프로그램뿐만 아니라 대화 형 세션에서 작동시킬 수 있었다 콘솔 - 아니 tkinter)import list
a = list.object('list')
b = list.object('list')
print(a.list, b.list)
b.list.pop()
print(a.list, b.list)
input()
또한 copy.copy() 및 copy.deepcopy() 시도한 적이 있지만 작동하지!