実現したいこと
コンボボックス選択で動的にentryの数を変更したいです。
前提
コンボボックスでentry数を選べるようにしており、選ぶとその数通りにentryを増減したいのですが、実現できずにおります。
該当のソースコード
python
1from tkinter import * 2from tkinter import ttk 3 4def len_entry_change(event): 5global len_entry 6len_entry = kensuu_cbx_variable.get() 7 8root = Tk() 9 10len_entry = 10 11root_size_x = 150 12root_size_y = 20 + len_entry * 20 13entry_list = [] 14 15root.geometry(str(root_size_x)+"x"+str(root_size_y)) 16 17main_frame = Frame(root, width = root_size_x, height = root_size_y) 18main_frame.grid(row=0,column=0) 19 20for i in range(len_entry): 21entry_list.append(Entry(main_frame,width=20)) 22entry_list[i].grid(row=0 + i,column=0) 23 24kensuu_list = ['10','15','20'] 25kensuu_cbx_variable = StringVar() 26kensuu_combobox = ttk.Combobox(main_frame,values=kensuu_list,width=3,textvariable=kensuu_cbx_variable,justify=CENTER) 27kensuu_combobox.grid(row=1+i,column=0) 28kensuu_combobox.bind('<<ComboboxSelected>>',len_entry_change) 29kensuu_combobox.current(0) 30 31root.mainloop()
試したこと
ComboboxSelectedイベントでentry数を格納している変数(len_entry)の中身を変更しているのですが、entryの数が変わりません。
解決策を教えてください。
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー