代码之家  ›  专栏  ›  技术社区  ›  Code_Sipra

在simpledialog中添加默认值。在Python 3中使用tkinter的askstring

  •  6
  • Code_Sipra  · 技术社区  · 7 年前

    我正在尝试使用tkinter创建一个简单的文本框。下面是我正在尝试使用的代码。

    import tkinter as tk
    from tkinter import simpledialog
    
    root = tk.Tk() # Create an instance of tkinter
    
    start_date = simpledialog.askstring(title = "Test Title",
                                        prompt = "Entire Start Date in MM/DD/YYYY format:")
    

    下面是我得到的预期输出。

    enter image description here

    我的问题是,如何在默认情况下在空插槽中填充默认值,如下所示?

    enter image description here

    在R中,我可以使用下面的命令轻松地做到这一点。

    start_date <- winDialogString("Entire Start Date in MM/DD/YYYY format:", "01/31/2018")
    
    1 回复  |  直到 7 年前
        1
  •  20
  •   Da_Pz    7 年前

    你读过吗 this ?您可以提供 initialvalue 作为选项like

    simpledialog.askstring(title = "Test Title", prompt = "Entire Start Date in MM/DD/YYYY format:", initialvalue="whateveryouwant")