I have a main program window with a frame and a menu for invoking calculation modules.
from tkinter import Menu, Label, Tk, Frame, Scrollbar, Canvas, N, E, S
import runpy
import Bolt_connection
from importlib import reload
# Program window dimensions
root = Tk()
root.title("Name")
root.geometry("1260x700")
root.update()
MaxX = root.winfo_width()
MaxY = root.winfo_height()
canvas = Canvas(root, width=MaxX, height=MaxY, bg="white")
scroll_y = Scrollbar(root, orient="vertical", command=canvas.yview)
frame = Frame(canvas)
for i in range(50):
Label(frame).grid()
i += 1
canvas.create_window(0, 0, anchor='nw', window=frame)
canvas.update_idletasks()
canvas.configure(scrollregion=canvas.bbox('all'),
yscrollcommand=scroll_y.set)
canvas.grid()
scroll_y.grid(row=0, sticky=E + N + S)
main_menu = Menu()
# Submenu for Export to...
file_menu = Menu(tearoff=0)
help_menu = Menu(file_menu, tearoff=0)
help_menu_export_to = Menu(help_menu, tearoff=0)
help_menu_export_to.add_command(label="Excel")
help_menu_export_to.add_command(label="Word")
def start_bolt_connection():
import Bolt_connection
def start_key_connection():
import Key_connection
# Submenu for Part calculation selection
calculation_selection_menu = Menu(tearoff=0)
help_menu2 = Menu(calculation_selection_menu, tearoff=0)
help_menu2_part_calculation_selection = Menu(help_menu2, tearoff=0)
B2 = help_menu2_part_calculation_selection.add_command(label="Bolted (screw) connection", command=start_bolt_connection)
help_menu2_part_calculation_selection.add_command(label="Key connection", command=start_key_connection)
help_menu2_part_calculation_selection.add_command(label="Pinned connection")
# File menu
file_menu.add_command(label="New")
file_menu.add_command(label="Save")
file_menu.add_cascade(label="Export to...", menu=help_menu_export_to)
file_menu.add_command(label="Open")
file_menu.add_command(label="Exit")
# Main menu
main_menu.add_cascade(label="File", menu=file_menu)
main_menu.add_cascade(label="About")
main_menu.add_cascade(label="Help")
main_menu.add_cascade(label="Part calculation selection", menu=help_menu2_part_calculation_selection)
runpy.run_module('Bolt_connection')
root.config(menu=main_menu)
root.mainloop()
I want to see a window that looks like this when the program starts. Then, when you click on one of the menu buttons (for example, Key connection), the frame should update and display the graphical interface of the new module. After clicking the window should look like this.
The problem is that when the graphic part of the new module is displayed, the graphic part of the old module is not erased and they overlap each other. How to make the program delete the graphic part of the old module? The grid_remove()
and reload()
functions do not help.
An additional explanation of what I want to get when I run the program.
- Program starts.
- The main window appears with the calculation module already running, installed by default. In this case, "Bolt connection". The window should now look like this.
- The user selects one of the calculation modules from the menu. In this case, "Key connection". The graphic part of the previous module is erased, and the new module is displayed. The window should now look like this.
UPD
For a better understanding of the problem, add a link to google drive where the project files are located.
https://drive.google.com/drive/folders/110OrRqlfzGmswg8cGHO3-C4VxfRj1sos?usp=sharing
In this folder there are two txt files with the code of the exported modules, so that you do not have to download the project to your computer and run it .
See Question&Answers more detail:
os