I have a very lengthy python script that contains all of the features of my tool and I'm trying to split it by its functions into multiple files which later can be imported and to make further development easier. For now, I have 2 files. One will be the main execution file and the other one is the file to contains general functions.
main.py
from tkinter import *
from tkinter import filedialog, ttk
from PIL import ImageTk, Image
import pandas as pd
import vaex
from pyexcelerate import Workbook
from pyxlsb import open_workbook as open_xlsb
from math import ceil
from datetime import datetime
import win32com.client
import os
import re
import general
if __name__ == '__main__':
w=Tk()
w.geometry('900x500')
w.resizable(0,0)
w.title('Excel Processor')
general.Home(w)
img1 = ImageTk.PhotoImage(Image.open("C:\\class_testing\\assets\\open.png"))
Button(w,command=general.ToggleWin(w),image=img1, border=0).place(x=5,y=10) <-- the problem is when I pass the class to command it displays the toggle menu frame even when it's not clicked
w.mainloop()
general.py
from tkinter import *
from tkinter import filedialog, ttk
from PIL import ImageTk, Image
import pandas as pd
import vaex
from pyexcelerate import Workbook
from pyxlsb import open_workbook as open_xlsb
from math import ceil
from datetime import datetime
import win32com.client
import os
import re
import tkinter as tk
class BulletLabel(Label):
def __init__(self, master, *args, **kwargs):
text = kwargs.pop('text', '')
kwargs['text'] = self.bulletise(text)
Label.__init__(self, master, *args, **kwargs)
def bulletise(self, text):
if len(text) == 0:
return ''
lines = text.split('\n')
parts = []
for line in lines:
parts.extend(['\u2022', line, '\n'])
return ''.join(parts)
def configure(self, *args, **kwargs):
text = kwargs.pop('text', '')
if text != '':
kwargs['text'] = self.bulletise(text)
Label.configure(*args, **kwargs)
class Home(tk.Frame):
def __init__(self,master):
tk.Frame.__init__(self, master)
self.f2=Frame(master, width=900,height=455, background='white')
self.f2.pack()
self.f2.place(x=0, y=50)
self.label_title = Label(master,text='EXCEL PROCESSOR', font=('Calibri', 14, 'bold'), fg='#EE4D2D')
self.label_title.place(x=80,y=11)
self.label_menu = Label(master,text='Welcome!', font=(None, 10, 'bold'), fg='#EE4D2D', background='white')
self.label_menu.place(x=80,y=70)
self.instruct_text="Excel Processor is an offline data processing tool that allows you to do excel functions to your data in a faster way. "+\
"It is built as a desktop application on windows operating system. The current version includes eight features:"
self.label_instruct = Label(master, text=self.instruct_text, wraplength=740, justify='left', font=(None, 10), background='white')
self.label_instruct.place(x=80,y=100)
self.blabel = BulletLabel(master, text=" Lookup - do excel lookup function between two large files.\n "+\
"Merge - merge similar files with the same column names into one file.\n "+\
"Filter - filter data based on condition.\n "+\
"Convert - convert xlsx files to csv or the other way around.\n "+\
"Column operations - perform operations to create another column.\n "+\
"Count appearances - count value appearances in a column.\n "+\
"Split >1m rows data - split a table that contains more than one million rows of data.\n "+\
"Split between sheets - split an excel file that contains more than one sheet.\n "+\
"Split table by column - split a table by unique values of a column.\n "+\
"Split tables in 1 sheet - split an excel file that contains more than one table in one sheet.",
wraplength=740, justify='left', font=(None, 10), background='white')
self.blabel.place(x=80, y=140)
def page_home(f1p):
f1p.destroy()
Home()
ToggleWin()
class ToggleWin(tk.Frame):
def __init__(self,master):
tk.Frame.__init__(self,master)
self.f1=Frame(master,width=216,height=570,bg='#EE4D2D')
self.f1.place(x=0,y=0)