Dec-30-2018, 02:42 PM
Object oriented coding in python is a huge mountain for me.I need to study it a lot more to fully understand it.
GUI.py
If i just straight up import them,the code will run before the gui,because i have imported it on the top.
GUI.py
import tkinter as tk from tkinter import messagebox from sys import exit import os class GUI: def __init__(self,root): ####### Gets the requested values of the height and widht. windowWidth = root.winfo_reqwidth() windowHeight = root.winfo_reqheight() # Gets both half the screen width/height and window width/height positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2) positionDown = int(root.winfo_screenheight()/2 - windowHeight/2) # Positions the window in the center of the page. root.geometry("+{}+{}".format(positionRight, positionDown)) ##########---------------------- root.title("Αρχική είσοδος") self.maingui=tk.Frame(root) self.maingui.pack() self.Label1=tk.Label(self.maingui,text="Καλώς ορίσατε στο βοήθημα γραμμικής άλγεβρας") self.Label1.pack() self.Label2=tk.Label(self.maingui,text="Παρακαλώ,διάλεξε μία από τις επιλογές") self.Label2.pack() ## self.sum_button=tk.Button(self.maingui,text="Πρόσθεση",command=self.sum_py) self.sum_button.pack(fill="both",expand=1) ## self.afairesh_button=tk.Button(self.maingui,text="Αφαίρεση",command=self.afairesi_py) self.afairesh_button.pack(fill="both",expand=1) ## self.pollaplasiasmos_button=tk.Button(self.maingui,text="Πολλαπλασιαμός Πίνακα",command=self.pollaplasiamos_py) self.pollaplasiasmos_button.pack(fill="both",expand=1) ## self.quit_button=tk.Button(self.maingui,text="Έξοδος",command=self.popupmsg) self.quit_button.pack(fill="both",expand=1) def centered(self): # Gets the requested values of the height and widht. windowWidth = root.winfo_reqwidth() windowHeight = root.winfo_reqheight() print("Width",windowWidth,"Height",windowHeight) # Gets both half the screen width/height and window width/height positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2) positionDown = int(root.winfo_screenheight()/2 - windowHeight/2) # Positions the window in the center of the page. root.geometry("+{}+{}".format(positionRight, positionDown)) def kill(self): self.centered() root.destroy() popup.destroy() exit(0) def sum_py(self): root.withdraw() import prosthesi def afairesi_py(self): root.withdraw() import afairesh def pollaplasiamos_py(self): root.withdraw() import pollaplasiasmos def popupmsg(self): global popup root.withdraw() popup = tk.Tk() popup.title("Εξοδος") popup.iconbitmap('warn_img.ico') popup.geometry("200x100") warn = tk.Label(popup, text="Έξοδος?",) warn.pack() Yes= tk.Button(popup,text="Ναί",command =self.kill) Yes.pack() No= tk.Button(popup,text="Όχι",command = self.switch) No.pack() popup.resizable(0,0) popup.mainloop() def switch(self): popup.destroy() root.deiconify() #-------------- if __name__ == '__main__': root=tk.Tk() guitest=GUI(root) root.mainloop()Module that must be imported
from tkinter import * import numpy as np import os import sys import GUI import subprocess import importlib class MyApp: def __init__(self,root): ####### Gets the requested values of the height and widht. windowWidth = root.winfo_reqwidth() windowHeight = root.winfo_reqheight() # Gets both half the screen width/height and window width/height positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2) positionDown = int(root.winfo_screenheight()/2 - windowHeight/2) # Positions the window in the center of the page. root.geometry("+{}+{}".format(positionRight, positionDown)) #### there is a lot more but there are just more functionsThe thing that is concerning me is the bottom of the module file
root=Tk() myapp=MyApp(root) root.mainloop()Should i add
if __name__ == "__main__"??
If i just straight up import them,the code will run before the gui,because i have imported it on the top.