Help with dealing with imported data

I’m trying to create a prog that can take the data from (open) in the menu bar and then can edit and
plot it but always have issues!!

import os
from tkinter import *
import pandas as pd
from tkinter import filedialog

#prog name
gsp = Tk()
gsp.title('Geos Platform')
# gsp.state('zoomed')
#gsp.iconbitmap('E:\Restmar\earth.ico')

#create menu bar
my_menu = Menu(gsp)

file_menu = Menu(my_menu, tearoff=0)
my_menu.add_cascade(label= "File ", menu=file_menu)

file_menu.add_command(label= "New")
file_menu.add_command(label= "Open", command=lambda: open_the_file())
file_menu.add_separator()
file_menu.add_command(label= "Save")
file_menu.add_separator()
file_menu.add_command(label= 'Exit', command=gsp.quit)

method_choice = Menu(my_menu, tearoff=0)
my_menu.add_cascade(label= "Method", menu=method_choice)

def r_method():
     pass
def g_method():
    pass
def gg_method():
    pass
def s_method():
    pass

method_choice.add_command(label= "r", command= r_method)
method_choice.add_separator()
method_choice.add_command(label= "g", command= r_method)
method_choice.add_separator()
method_choice.add_command(label= "gg", command= g_method)
method_choice.add_separator()
method_choice.add_command(label= "s", command= s_method)

about_info = Menu(my_menu, tearoff=0)
my_menu.add_cascade(label= "Help", menu=about_info)

def about_soft():
    pass
def about_devo():
    pass

about_info.add_command(label= "About Software", command= about_soft)
about_info.add_separator()
about_info.add_command(label= "About Devoloper", command= about_devo)
gsp.config(menu=my_menu)

#Open file function
def open_the_file():
    open_file = filedialog.askopenfilename(title='Open Excel File',initialdir='/',
        filetype=(("Excel Sheet",".xlsx"),("Excel Sheet",".xlsm"),("Excel Sheet",".xls") ))
    global xlsx
    xlsx = pd.ExcelFile(open_file)
    read_excelr()
    
def read_excelr():
    df=pd.read_excel(xlsx, index_col=0)
    print(df)
# HERE IS THE QUESTION
gsp.mainloop()

How can I get out the data from that function and work with and even edit it!
another last question when I import one single part of another module it imports all if it!!

from xxx import func!

Hope to find an answer

One gets data out of a function by returning it or by altering a global structure. See the doc tutorial for examples.

1 Like

First of all, Thank you for the response…

I’ve tried to use the return and the global before!!!
for the return: when I use the return and try to simply print the output to see what would happen: Always when I start the prog there is the open file window shows with no control
that why I neglected it for a while! :slight_smile:

when I use the global i’ve to call the function before excution which will ask to open
a directory once I open the file, AGAIN!!

For ex:

def open_the_file():
    open_file = filedialog.askopenfilename(title='Open Excel File',initialdir='/',
        filetype=(("Excel Sheet",".xlsx"),("Excel Sheet",".xlsm"),("Excel Sheet",".xls") ))
    global xlsx
    xlsx = pd.ExcelFile(open_file)
    read_excelr()
    
def read_excelr():
    global df    #The global df here it is
    df=pd.read_excel(xlsx, index_col=0)

open_the_file()  #I've to call this func to be able to use the global df which will ask to open a file once i run the prog
read_excelr()
print(df) ```