Tkinter,下拉菜单

时间:2019-05-07 00:35:49

标签: python tkinter

你好,我正在练习使用tkiter制作一个8球的python程序。我在创建随机响应的按钮上取得了成功,但是根据我的下拉菜单却无法正常工作。我试图使其在显示默认消息时将显示错误消息。谢谢!

我试图做一个函数,但是由于某种原因,它不是基于我的条件。

import Tkinter
from Tkinter import *
import random

# Set up the main (top) window's settings
window = Tk()
window.title("DR. Eight Ball")
window.geometry("1200x1200")
window.configure(bg='bisque4')


response = ["You have 15 minutes to live!",
            "Just put a band-aid on it",
            "Eh you're fine",
            "It, could be nothing...or cancer",
            "essential oils anyone?",
            "You are 100% healthy",
            "It's all in your head",
            "If life gives you lemons, a simple operation can give you melons",
            "Have you tried accupunture?",
            "you have a cold, now that will be $10,000" ]

ddvar = StringVar(window)
ddchoices = ['Terrible', 'Just Fine','Wonderful']
lab1 = Label(window, text = 'The Doctor is in! How do you feel?', bg =                 
'gray17', fg = 'ghost white', font='arialbold')
popM = OptionMenu(window, ddvar, *ddchoices) 
ddvar.set('Choose an Option:')



def dropdown(*args):
    return(ddvar.get())

ddvar.trace('w', dropdown)


def diagnosis():
    error = "I NEED YOUR HEALTH STATUS!"
    x = random.choice(response)

    if ddchoices <> 'Choose an Option:':
            x = random.choice(response)
            textbox.delete(0,END)
            textbox.insert(0,str(x))
    else:
            textbox.insert(0,error)

#text box    
textvar1 = StringVar()
textbox = Entry(window,bg='Black', fg='Red', font='freesansbold') 

btn1 =  Button(window, text='Get Answer', bg='darkBlue', fg='Red',     
font='freesansbold', command=diagnosis)


lab1.pack()
popM.pack()
btn1.pack()
textbox.pack()

该文本框显示了我的回答中的随机选择,但不会显示错误消息。

0 个答案:

没有答案