0

I'm programming a GUI with tkinter, but I'm a noob with this. My GUI-code is kinda big so I wanted to seperate the functions and the GUI code - so far so good, but when I want to import the Functions I get a NameError, otherwise if I put my functions into the GUI code it automatically starts even if I assigned it to a Button command. The autostart problem also occurs if I seperate it, otherwise I wouldn't be getting the Error on start I guess.

I imported following in both files:

import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
#from tkcalendar import Calendar, DateEntry
import pandas as pd
import numpy as np

and in the GUI also: from PerunaFunctions import *

Code piece of the Function:

def show_file(tree):
    file = filedialog.askopenfilename()
    df = pd.read_csv(file,sep=';',header=2)
    
    df_col = df.columns.tolist()
    tree['columns']=df_col
    counter = len(df)
    for n in range(len(df_col)):
        tree.column(df_col[n],width=100)
        tree.heading(df_col[n],text=df_col[n])

        for i in range(counter):
            rowLabels = df.index.tolist()
            tree.insert('', i, text=rowLabels[i], values=df.iloc[i,:].tolist())
    return tree   

Code piece of the GUI:

tree_importpeiler_3 = ttk.Treeview(importpeiler_frame, height=10)
ttk.Button(importpeiler_frame,text='CSV-Datei einlesen',command=show_file(tree_importpeiler_3)).grid(row=0,column=0)

I actually thought it wouldn't be a problem with the autostart at all, because in my opinion it should only start when I press the button. for importing the functions I tried a differen function which doesn't need any modules, that worked but I don't understand why I get that Error because I imported all the modules I need. The show_file function works when I use it within the GUI-code, but autostarts.

Tom
  • 11
  • 3
  • yeah thanks! at least the problem with the autostart, now I'm still struggling with the imported module error – Tom Feb 21 '23 at 07:59

0 Answers0