python-2.7 - 如何从另一个 gui 填充 tkinter 中的输入框
问题描述
我导入了一个名为“select_date”的函数。此函数运行一个 gui 应用程序 (calendar-datepicker) 并返回选定的年、月和日(该函数经过充分测试)。我想用所选日期填充 tkinter 条目。当我运行代码时,条目未填写。但是,当我们不使用 select_date 函数来获取日期时,我们使用定义的值,例如 date="yyyy/mm/dd"(在代码中注释),程序按预期运行并且条目填充为“yyyy/mm /dd”。
import Tkinter as tk
from mycalendar import select_date
root = tk.Tk()
root.title("My App")
root.geometry("400x400")
w = tk.Label(root, text="Aerosol Optical Depth & Trends")
w.grid(column = 0, row = 100)
w.pack()
# ~ date="yyyy/mm/dd"
e = tk.Entry()
e.pack()
e.delete(0, tk.END)
year,month,day=select_date(myinput="From Date")
date=str(year)+'/'+str(month)+'/'+str(day)
e.insert(0, date)
root.mainloop()
select_date 在以下代码中:
try:
import tkinter as tk
from tkinter import ttk
except ImportError:
import Tkinter as tk
import ttk
import datetime
from tkcalendar import Calendar, DateEntry
import tkMessageBox
def select_date(myinput):
def example1():
def print_sel():
print(cal.selection_get())
global year
global month
global day
year=cal.selection_get().year
month=cal.selection_get().month
day=cal.selection_get().day
#~ tkMessageBox.askyesno("Date Select", cal.selection_get())
root.withdraw()
result = tkMessageBox.askyesno("Date Select", cal.selection_get())
if result == True:
root.destroy()
top = tk.Toplevel(root)
cal = Calendar(top, font="Arial 14", selectmode='day', locale='en_US',
cursor="hand1", year=datetime.date.today().year, month=datetime.date.today().month, day=datetime.date.today().day)
cal.pack(fill="both", expand=True)
ttk.Button(top, text="select", command=print_sel).pack()
root = tk.Tk()
ttk.Button(root, text=myinput, command=example1).pack(padx=10, pady=10)
root.mainloop()
return year,month,day
解决方案
推荐阅读
- c# - 如何使用标签从数据库中填充 C# 中的表
- javascript - 如何在 React Native 中与父组件同时重置子类组件中的状态?
- css - 在 CSS 中限制背景图像的最大宽度
- vb.net - 模拟红外遥控音量按钮
- sql - 对于 Oracle 中的每个地址更改,我应该如何处理这个开始和结束日期?
- python - Django HTML表单不填充变量
- node.js - 猫鼬在快递中使用模块导出后创建空文档
- ionic-framework - Ionic 4 PWA 和原生 android/ios 服务工作者缓存
- ios - Xcode - 已达到免费开发配置文件的最大应用程序数量(错误?)
- r - 如何使用 ggplot2 绘制时间序列数据中缺失的日期?