python - 在 Python 3 中使用 tkinter 在 simpledialog.askstring 添加默认值

标签 python python-3.x tkinter tk-toolkit

我正在尝试使用 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")

最佳答案

你读过this吗? ?您可以提供初始值作为选项,例如

simpledialog.askstring(title = "测试标题",prompt = "整个开始日期,格式为 MM/DD/YYYY:",initialvalue="whateveryouwant")

关于python - 在 Python 3 中使用 tkinter 在 simpledialog.askstring 添加默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49190088/

相关文章:

python - Django中忘记密码的实现

python - PyAutoGUI 定位命令返回错误的图像识别坐标

python - 如何使用 tkinter 返回 Base 64 编码图形的高度和宽度

Python tkinter - 在 Canvas 中移动对象

python - 在文本框中搜索单词并将光标移动到文本框中的下一个匹配项?

python - 为什么 "5 in range(5,6) in [range(5,6)]"返回 True?

python - 如何提高 scikit-learn 中预测的准确性

python - “jupyter notebook”命令在 Linux 上不起作用

python-3.x - 在 Python + Selenium + Firefox WebDriver 上配置代理

Python imaplib 搜索带有日期和时间的电子邮件