Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tkcalendar是tkinter的新手,如何使用我看到的教程存储用户输入的日历。我对python还是很陌生_Python_Tkinter_Tkcalendar - Fatal编程技术网

tkcalendar是tkinter的新手,如何使用我看到的教程存储用户输入的日历。我对python还是很陌生

tkcalendar是tkinter的新手,如何使用我看到的教程存储用户输入的日历。我对python还是很陌生,python,tkinter,tkcalendar,Python,Tkinter,Tkcalendar,我有以下正在进行的代码,我试图让用户从日历中输入日期,但我对使用tkinter、tkcalendar非常陌生,因此我不确定如何将输入存储为变量,以便传递到其他地方使用: def addGameTimeInfo(): #week_number = input('Enter the week number of this game:') #game_date = input('Enter the date for this game(YYYY/MM/DD):') #seaso

我有以下正在进行的代码,我试图让用户从日历中输入日期,但我对使用tkinter、tkcalendar非常陌生,因此我不确定如何将输入存储为变量,以便传递到其他地方使用:

def addGameTimeInfo():
    #week_number = input('Enter the week number of this game:')
    #game_date = input('Enter the date for this game(YYYY/MM/DD):')
    #season_number = input('Enter Season Number for this game:')
    def calendar_view():
        def print_sel():
            print(cal.selection_get())

        top = Toplevel(root)

        cal = Calendar(top,
                       font="Arial 14", selectmode='day',
                       cursor="hand1")
        cal.pack(fill="both", expand=True)
        ttk.Button(top, text="ok", command=print_sel).pack()
    def dateentry_view():
        def print_sel(e):
            print(cal.get_date())
        top = Toplevel(root)
        
        ttk.Label(top, text = 'Choose date').pack(padx=10,pady=10)
        cal = DateEntry(top, width=12, background = 'darkblue',
                       foreground ='white',borderwidth=2)
        cal.pack(padx=10,pady=10)
        cal.bind('<<DateEntrySelected>>',print_sel)
    
    root = Tk()
    s = ttk.Style(root)
    s.theme_use('clam')
    
    ttk.Button(root, text = 'Calendar',command=calendar_view).pack(padx=10,pady=10)
    ttk.Button(root,text='DateEntry',command=dateentry_view).pack(padx=10,pady=10)
    root.mainloop()
def addGameTimeInfo():
#周数=输入('输入此游戏的周数:')
#游戏日期=输入('输入此游戏的日期(YYYY/MM/DD):')
#季节号=输入('输入此游戏的季节号:')
def calendar_view():
def print_sel():
打印(校准选择\获取())
顶层=顶层(根)
cal=日历(顶部,
font=“Arial 14”,选择mode='day',
cursor=“hand1”)
校准包装(fill=“两者”,expand=True)
ttk.按钮(顶部,text=“ok”,command=print\u sel).pack()
def dateentry_view():
def打印选择(e):
打印(校准获取日期())
顶层=顶层(根)
ttk.Label(顶部,文本='选择日期').pack(padx=10,pady=10)
cal=DateEntry(顶部,宽度=12,背景='darkblue',
前景(白色),边框宽度=2)
校准组件(padx=10,pady=10)
校准绑定(“”,打印选择)
root=Tk()
s=ttk.Style(根)
s、 主题使用(“蛤蜊”)
ttk.按钮(根,文本='Calendar',命令=Calendar\u view).pack(padx=10,pady=10)
ttk.Button(root,text='DateEntry',command=DateEntry\u view).pack(padx=10,pady=10)
root.mainloop()

我在另一篇文章中看到了这一点,但我不能评论,因为我是一个新用户,否则我会在那里发表文章。谢谢大家!

另外,我忘了说,当我试图返回cal并执行cal.get_date()时,我会得到错误:无效的命令名“!dateentry”。我想知道,为什么在函数内部调用时不出现错误?另外,我忘了说,当我尝试返回cal并执行cal.get_date()时,会出现错误:无效的命令名“!dateentry”。我想知道,为什么我在函数内部调用时没有得到这个错误?