为什么tkinter python组合框代码返回错误的输出?

时间:2018-09-13 10:27:13

标签: python tkinter

我希望第二个组合框cbo_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

该如何解决?

0 个答案:

没有答案