您要求的是完整的算法,实际上是完整的编程,除了如何操作您的数据.我不知道堆栈溢出中是否允许这种问题.
如有需要,我已作了解释.我无法判断代码,因为您尚未提供要执行的数据和函数.因此,可能存在错误.实时进行相应的更正.
注:单独添加列标题(即Pandas 索引)的小部件,因为我忘了添加.使用标签和网格方法.
根据您的需求定制Widget.
编辑:我犯了一个错误,在缺省情况下执行函数RUN_Functions,假设它在缺省情况下运行时,会在给定所有输入后继续运行.后来,我意识到它不会,因为函数Run_Functions只会运行一次,然后停止.现在,我已经编辑了代码.现在,输入var1、var2、var3、var4、var5和var6与'<Leave>'
和Run_Function绑定在一起.因此,在离开每个条目后,Run_Functions将运行并判断状态.
也许,有些人会想,为什么所有条目都要绑定,为什么不只绑定最后一个条目.这是因为,有时用户可能会先填写最后一个条目,然后再填写前一个条目.
from tkinter import *
from tkinter import ttk
import tkinter as tk
#import file fialogue module to select file
from tkinter import filedialog as fd
#define functions before the design part
def getFile():
#declare the variable got_file global to use in other functions
global got_file
#assuming the file_type is image file. change the file type accordingly.
fileType = [('image', '*.png'),('image', '*.jpg'),('image', '*.jpeg')]
#open a popup box to select file
got_file = fd.askopenfilename(filetypes=fileType)
#show the selected file in the widget selected_file
selected_file.configure(text = got_file)
#function to disable vars
def disable_vars():
for x in [var1, var2, var3, var4, var5, var6, output_frame]: x['state'] = DISABLED
def enable_vars(*vars):
for x in vars: x['state'] = NORMAL
def run_functions():
if rad_var.get() == 'function 1':
if all(x.get() != '' for x in [var1, var2, selected_file]):
function_1()
elif radio_var.get == 'function 2':
if all(x.get() != '' for x in [var3, var4, var5, var6, selected_file])
function_2()
else: pass
def function_1():
#declare global for got_file as we should use here
global got_file
#enable frame where the table/graph to be displayed
output_frame['state'] = NORMAL
'''
Your code for dataframe here
'''
#convert the dataframe to matrix
matrix = df.to_numpy()
for i,x in enumerate(matrix):
for j,y in enumerate(x):
cell = Entry(output_frame, width=20, fg='blue',borderwidth=1, relief="solid")
cell.grid(row=i, column=j)
cell.insert(END, y)
def function_2():
#Use the same method followed in function_1
root= Tk()
root.geometry("800X900")
root.config(bg='light blue')
root.title('Dashboard')
#run the function disable_vars immediately while opening the app
root.after_idle(disable_vars)
frame = tk.Frame(root,bg='light blue')
frame.pack(padx=10,pady=10)
#assuming all the widgets are there in the frame
var1 = Entry(frame)
var1.pack()
var2 = Entry(frame)
var2.pack()
radio_var = tk.StringVar()
fun1 = Radiobutton(frame, text='function 1', variable=radio_var, value= 'function 1', command = lambda: enable_vars([var1, var2]))
fun1.pack(side='top')
var3 = Entry(frame)
var3.pack()
var4 = Entry(frame)
var4.pack()
var5 = Entry(frame)
var5.pack()
var6 = Entry(frame)
var6.pack()
rad_var = = tk.StringVar()
fun1 = Radiobutton(frame, text='function 2',variable=radvar, value= 'function 2', command = lambda: enable_vars([var3, var4, var5, var6]))
fun1.pack(side='top')
file_label = Label(frame,text='Input_File')
file_label.pack(side='top')
selected_file = Label(frame, text = '')
selected_file.pack(side= 'top')
file_btn = Button(tab1, width=25, text='select the File', command=getFile)
prgbtn.pack(side='top', padx=10, pady= 0)
output_frame = Frame(root)
output_frame.pack()
for x in [vars1, vars2, vars3, vars4, vars5, vars6]:
x.bind('Leave', run_functions)
root.mainloop()