Найти - Пользователи
Полная версия: Нужна помощь по прогамме.
Начало » Центр помощи » Нужна помощь по прогамме.
1
Bloodies
Нуждаюсь в помощи.
В общем, проблема такая:
В вузе задали задание написать прогу, так как я только начал свое обучение, то немного не понимаю полной картины и строения кода. Нужно чтоб при нажатии на кнопку работала команда и открывалось следующее окно, а предыдущее закрывалось.
От безысходности нашел примерно такой код и немного изменил его, но столкнулся с проблемой, если добавлять в каждый фрейм дополнительные картинки или кнопки, то они не исчезают.

Если не сложно, то помогите

З.Ы. Надо код который будет открывать дочернее окно но закрывая предыдущее с возможностью добавления чего либо, либо этот же код, но чтоб фрейм для редактирования был больше


from tkinter import *
import tkinter
import tkinter.ttk

def create_widgets_in_first_frame():
# Create the label for the frame


# Create the button for the frame
first_window_next_button = tkinter.Button(first_frame, text=“1”, command=call_second_frame_on_top)
first_window_next_button.grid(column=0, row=0, pady=10, padx=10, stickytkinter.N))
first_window_next_button = tkinter.Button(first_frame, text=“2”, command=call_third_frame_on_top)
first_window_next_button.grid(column=0, row=1, pady=10, padx=10, stickytkinter.N))
first_window_next_button = tkinter.Button(first_frame, text=“3”, command=call_fourth_frame_on_top)
first_window_next_button.grid(column=1, row=0, pady=10, padx=10, stickytkinter.N))
first_window_next_button = tkinter.Button(first_frame, text=“4”, command=call_fifth_frame_on_top)
first_window_next_button.grid(column=1, row=1, pady=10, padx=10, stickytkinter.N))
first_window_quit_button = tkinter.Button(first_frame, text=“Exit”, command=quit_program)
first_window_quit_button.grid(column=2, row=2, pady=10, padx=10, stickytkinter.N))


def create_widgets_in_second_frame():
# Create the label for the frame


# Create the button for the frame
second_window_back_button = tkinter.Button(second_frame, text=“1”, command=call_first_frame_on_top)
second_window_back_button.grid(column=0, row=1, pady=10, padx=10, stickytkinter.N))
second_window_next_button = tkinter.Button(second_frame, text=“Next”, command=quit_program)
second_window_next_button.grid(column=1, row=1, pady=10, padx=10, stickytkinter.N))

def create_widgets_in_third_frame():
# Create the label for the frame

# Create the button for the frame
third_window_back_button = tkinter.Button(third_frame, text=“1”, command=call_first_frame_on_top)
third_window_back_button.grid(column=0, row=1, pady=10, padx=10, stickytkinter.N))
third_window_quit_button = tkinter.Button(third_frame, text=“Quit”, command = quit_program)
third_window_quit_button.grid(column=1, row=1, pady=10, padx=10, stickytkinter.N))

def create_widgets_in_fourth_frame():
# Create the label for the frame

# Create the button for the frame
fourth_window_back_button = tkinter.Button(fourth_frame, text=“1”, command=call_first_frame_on_top)
fourth_window_back_button.grid(column=0, row=1, pady=10, padx=10, stickytkinter.N))
fourth_window_quit_button = tkinter.Button(fourth_frame, text=“Quit”, command=quit_program)
fourth_window_quit_button.grid(column=1, row=1, pady=10, padx=10, stickytkinter.N))

def create_widgets_in_fifth_frame():
# Create the label for the frame

# Create the button for the frame
fifth_window_back_button = tkinter.Button(fifth_frame, text=“1”, command=call_first_frame_on_top)
fifth_window_back_button.grid(column=0, row=1, pady=10, padx=10, stickytkinter.N))
fifth_window_quit_button = tkinter.Button(fifth_frame, text=“Quit”, command=quit_program)
fifth_window_quit_button.grid(column=1, row=1, pady=10, padx=10, stickytkinter.N))

def call_first_frame_on_top():
# This function can be called only from the second window.
# Hide the second window and show the first window.
second_frame.place_forget()
third_frame.place_forget()
fourth_frame.place_forget()
fifth_frame.place_forget()
first_frame.place(relx=0.3, rely=0.3)

def call_second_frame_on_top():
# This function can be called from the first and third windows.
# Hide the first and third windows and show the second window.
first_frame.place_forget()
second_frame.place(relx=0.3, rely=0.3)

def call_third_frame_on_top():
# This function can only be called from the second window.
# Hide the second window and show the third window.
first_frame.place_forget()
third_frame.place(relx=0.3, rely=0.3)

def call_fourth_frame_on_top():
# This function can only be called from the second window.
# Hide the second window and show the third window.
first_frame.place_forget()
fourth_frame.place(relx=0.3, rely=0.3)

def call_fifth_frame_on_top():
# This function can only be called from the second window.
# Hide the second window and show the third window.
first_frame.place_forget()
fifth_frame.place(relx=0.3, rely=0.3)

def quit_program():
root_window.destroy()

###############################
# Main program starts here #
###############################

# Create the root GUI window.
root_window = tkinter.Tk()

root_window.title(“Калькулятор квадратов”)
root_window.geometry(“750x450+300+200”)
root_window.resizable(False, False)


# Create frames inside the root window to hold other GUI elements. All frames must be created in the main program, otherwise they are not accessible in functions.
first_frame = tkinter.ttk.Frame(root_window, width=750, height=450+300+200)
first_frame.place(relx=0.3, rely=0.3)

second_frame = tkinter.ttk.Frame(root_window, width=750, height=450+300+200)
second_frame.place(relx=0.3, rely=0.3)

third_frame = tkinter.ttk.Frame(root_window, width=750, height=450+300+200)
third_frame.place(relx=0.3, rely=0.3)

fourth_frame = tkinter.ttk.Frame(root_window, width=750, height=450+300+200)
fourth_frame.place(relx=0.3, rely=0.3)

fifth_frame = tkinter.ttk.Frame(root_window, width=750, height=450+300+200)
fifth_frame.place(relx=0.3, rely=0.3)

# Create all widgets to all frames
create_widgets_in_first_frame()
create_widgets_in_second_frame()
create_widgets_in_third_frame()
create_widgets_in_fourth_frame()
create_widgets_in_fifth_frame()


# Hide all frames in reverse order, but leave first frame visible (unhidden).
second_frame.place_forget()
third_frame.place_forget()
fourth_frame.place_forget()
fifth_frame.place_forget()

# Start tkinter event - loop
root_window.mainloop()
DamMercul
щит, почему не смотря на самый первый топик в закрепе все равно умудряются забывать теги
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB