首页 > 解决方案 > 如何检查 OptionMenu 的选项是什么?

问题描述

我想检查下拉菜单设置为哪个选项。程序检查日期和下拉菜单选项并相应地设置一个字符串。现在代码看起来像这样。有没有办法可以检查下拉菜单的值?


class FrameStart1(tkinter.Frame):
    image = PhotoImage(file='C:/Users/plarkin2020334/Pictures/DQ_Logocp.png')
    def __init__(self, parent, *args, **kwargs):
        tkinter.Frame.__init__(self, parent, *args, **kwargs)
        Label(self, image=self.image).place(relx=0, rely=0, anchor=NW)
        Label(self, text="Enter any additional Instructiuons for the day:", background="#3f49e5").place(relx=.0, rely=.45)
        self.info = tkinter.StringVar()
        self.entry = tkinter.Entry(self, textvariable=self.info).place(relx=.0, rely=.51)
        Button(self, text="Add to Todays List", command=self.add_list).place(relx=.24, rely=.51)
        tkvar = StringVar()
        self.choices = {'Open', 'Day', 'Close'}
        self.opt = OptionMenu(self, tkvar, *self.choices, ).place(relx=.0008 , rely=.572)

    def add_list(self):
        global Day
        if date.today().weekday() == 2 and self.opt == 'Open':
            Day = "List_Wednesday_Morn.txt"
        with open(Day, "r+") as file:
            for line in file:
                if not line.strip():
                    continue
                else:
                    file.write("\n" + self.info.get())

标签: pythontkinter

解决方案


推荐阅读