0

我的代码如下:

class insert_data(tk.Frame): 
    def __init__(self, parent, controller): 
        tk.Frame.__init__(self, parent)

        # create calender dropdown menu
        cal_input = DateEntry(
            self,
            width = 12,
            borderwidth = 2,
            year = 2020,
            background = 'blue'
        )
        cal_input.grid(row = 1, column = 1, padx = 10, pady = 5, sticky = 'ew')

我正在尝试从cal_input(日期输入小部件)获取值并将其打印在我的终端上。但是我不知道该怎么做。我不断收到错误。我试图调用类对象,但我仍然无法从日期输入小部件中获取值。谁能给我建议?任何帮助将不胜感激。

注意:这是我的完整代码 = https://pastebin.com/cYYtBx7b

4

1 回答 1

0

创建变量entry = StringVar()

text=entry.get()这会将您的输入存储在文本中

内部cal_input使用textvariable=entry

修改后的代码如下

class insert_data(tk.Frame): 
    def __init__(self, parent, controller): 
        tk.Frame.__init__(self, parent)

        entry = StringVar()

        # create calender dropdown menu
        cal_input = DateEntry(
            self,
            width = 12,
            borderwidth = 2,
            year = 2020,
            background = 'blue',
            textvariable=entry
        )
        cal_input.grid(row = 1, column = 1, padx = 10, pady = 5, sticky = 'ew')

        print(entry.get())
于 2020-09-20T16:38:20.680 回答