python-3.x - Python 3.8.2:filedialog.askopenfilename 和 ttk.Entry 冲突
问题描述
我正在尝试从excel文件中读取列表并将其放入组合框中,但是当我执行下面的代码时,无法用键盘填充条目,我应该先使用组合框或更改窗口并切换回激活条目并填写它。
代码和excel文件在下面的链接中。
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
import pandas
win = tk.Tk()
win.title('Label Frame ')
screen_width = int(win.winfo_screenwidth()/2)
screen_height = int(win.winfo_screenheight()/2)
win.geometry(f"{screen_width}x{screen_height}+0+0")
File_opned = filedialog.askopenfilename(title='Please select excel file.',
filetypes=[('excel File',['.xls', '.xlsx', '.xlsm', '.xltx','.xltm', '.xlam'])])
excel_data_df = pandas.read_excel(File_opned, sheet_name='Scenes')
file_Excel_list = excel_data_df['Scenes'].tolist()
label_frame = tk.LabelFrame(win, text='Test Infos ', bd=3, padx=10, pady=10)
label_frame.grid(row=0, column=0, padx=40)
cur_label1 = ttk.Label(label_frame, text = 'What is your name : ')
cur_label1.grid(row=0, column=0)
cur_label2 = ttk.Label(label_frame, text = 'Scenes : ')
cur_label2.grid(row=1, column=0)
cur_entrybox = ttk.Entry(label_frame, width=19, textvariable=tk.StringVar())
cur_entrybox.grid(row=0, column=1)
cur_combobox = ttk.Combobox(label_frame, width=16, values=file_Excel_list)
cur_combobox.grid(row=1, column=1)
def submit():
print(cur_entrybox.get())
print(cur_combobox.get())
submit_btn = ttk.Button(win, text='Submit', command=submit)
submit_btn.grid(row=1, columnspan=2)
for child in label_frame.winfo_children():
child.grid_configure(padx=4, pady=4)
win.mainloop()
解决方案
推荐阅读
- c# - 如何在 GMap.net 中将地图提供者设置为 OpenStreetMap
- excel - 事件每年发生的次数取决于开始日期和频率 (excel)
- java - 在大文本文件中查找文本数据的快速方法是什么?
- google-sheets - 当我尝试 STDEV、STDEVA、STDEVP、STDEVPA 时,表格对我的数据集做了奇怪的事情
- android - 使用 pydub+ffmpeg 编码的 M4a (mp4) 音频文件无法在 Android 上播放
- python - 如何使用 Python 2.7 在 anaconda 提示符中安装 zip(或 tag.gz)文件(我想安装 PyQt4 的版本)
- kotlin - Spring WebFlux,提取请求体
- google-apps-script - 如何使用 Google Apps 脚本检查 Google 表格中的 URL 重定向
- java - 测试中未提供 Hilt 依赖项
- postgresql - 如何将 SUM 添加到 typeorm 中的嵌套查询?