python - 如何检查 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())
解决方案
推荐阅读
- c++ - 遍历 std::set 中包含的所有不同值的三元组?
- angular - Angular 6:使用 httpclient 请求错误测试服务
- xamarin - 如何在 xamarin.ios 中长按 UITextView 后添加“全选”选项?
- c# - 在下一个控件之后按 Tab 移动到一个
- c# - 不要从实体框架显示项目到组合框
- android - 分享新闻链接
- linux - 在bash中注入带有特殊字符的变量
- c# - 如何将具有后期构建依赖项的 WPF 应用程序打包到 UWP 包中?
- python - 无法使用 pymongo 客户端在 Docker 中将 MongoDB 与 Flask 连接
- javascript - 从三个js中的特定点开始相机旋转