我希望第二个Comboxcbo_forecast_ps在选择第一个组合中的项目时显示某些值cbo_forecast_w。
from Tkinter import *
import tkMessageBox
import ttk
from ttk import *
masterframe =Tk()
# Create right frame for general information
rightFrame = Frame(masterframe,width
=600,height=300,borderwidth=2,relief=SOLID,)
rightFrame.place(x=610,y=0)
for_w_text =StringVar()
cbo_forecast_w = ttk.Combobox (rightFrame, textvariable=for_w_text)
cbo_forecast_w['values']=("cow","chicken","ant")
string_text =StringVar()
cbo_forecast_ps = ttk.Combobox (rightFrame,textvariable=string_text)
def choosestring():
forecast_w= for_well_text.get()
lbl_test.configure(text = forecast_w)
if forecast_w=="cow":
cbo_forecast_ps['values'] = ("single")
cbo_forecast_ps.current(0)
else:
cbo_forecast_ps['values'] = ("Short", "Long")
cbo_forecast_ps.current(0)
# I hope this is correct
cbo_forecast_w.bind("<<ComboboxSelected>>",choosestring())
我发现forecast_w没有从for_well_text.get(). 相反,它正在放弃PY_VAR2。
如何解决这个问题?