CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

02 March, 2024

Switching between two frames on seperate files in tkinter

 Programing Coderfunda     March 02, 2024     No comments   

I am writing a program where I have the opportunity, to switch between two frames which are one two separate Files. The main file is called "Main_Menu" while the other file is called "first_page". When I import the classes from both classes into each other, then I get an circular import which leads to the program not working. Does anybody have a solution? The codes to both files are under this Text.


Main_Menu.py
import tkinter as tk
from tkinter import PhotoImage

from second_page import SecondPage
from first_page import FirstPage

class Hauptfenster:
def init(self, root):
self.root = root self.root.title("Hauptfenster")

# Bild laden
self.background_image = PhotoImage(file="Background_Main.png")

# Größe des Bildes abrufen
self.width = self.background_image.width()
self.height = self.background_image.height()

# Haupt frame erstellen
self.main_frame = tk.Frame(self.root, width=self.width, height=self.height)
self.main_frame.pack_propagate(False) # Verhindert, dass der Rahmen seine Größe an die Widgets anpasst
self.main_frame.pack() # Packe den Haupt frame, um ihn sichtbar zu machen

# Hintergrundbild hinzufügen
self.background_label = tk.Label(self.main_frame, image=self.background_image)
self.background_label.place(x=0, y=0, relwidth=1, relheight=1) # Füllt das Bild den Rahmen aus

# Rahmen für den ersten Knopf erstellen
self.create_character_frame = tk.Frame(self.main_frame, bg="white", bd=0, relief="flat")
self.create_character_frame.place(relx=0.4, rely=0.7, anchor="center")

# Rahmen für den zweiten Knopf erstellen
self.Archiv_frame = tk.Frame(self.main_frame, bg="white", bd=0, relief="flat")
self.Archiv_frame.place(relx=0.6, rely=0.7, anchor="center")

# Rahmen für den schließen Button
self.close_frame = tk.Frame(self.main_frame, bg="white", bd=0, relief="flat")
self.close_frame.place(relx=0.5, rely=0.9, anchor="center")

# Rahmen für das Logo
self.logo_frame = tk.Frame(self.main_frame, bg="white", bd=0, relief="flat")
self.logo_frame.place(relx=0.5, rely=0.2, anchor="center")

# Text für den ersten Knopf hinzufügen
self.create_character_image = PhotoImage(file="character_text.png")
self.create_character_button = tk.Button(self.create_character_frame, image=self.create_character_image,
relief="flat", command=self.zeige_erste_seite)
self.create_character_button.pack(pady=10)

# Bild für den ersten Knopf hinzufügen

self.first_image = PhotoImage(file="Bild_eins.png")
self.first_image_label = tk.Label(self.main_frame, image=self.first_image, bd=0, highlightthickness=0)
self.first_image_label.place(relx=0.4, rely=0.511, anchor="center")

# Text für den zweiten Knopf hinzufügen
self.Archiv_image = PhotoImage(file="Archiv_Text.png") # Beispielbild, ersetze es mit deinem Bild
self.Archiv_button = tk.Button(self.Archiv_frame, image=self.Archiv_image, relief="flat",
command=self.zeige_zweite_seite)
self.Archiv_button.pack(pady=10)

# Bild für den zweiten Knopf hinzufügen
self.Sheet_image = PhotoImage(file="Bild_zwei.png")
self.Sheet_image_label = tk.Label(self.main_frame, image=self.Sheet_image, bd=0, highlightthickness=0)
self.Sheet_image_label.place(relx=0.6, rely=0.511, anchor="center")

# Button zum Schließen des Programms hinzufügen
self.close_image = PhotoImage(file="Escape.png")
self.close_button = tk.Button(self.close_frame, image=self.close_image, command=root.destroy, relief="flat")
self.close_button.pack(pady=10)

# Logo einfügen
self.logo_image = PhotoImage(file="logo.png")
self.logo_image_label = tk.Label(self.main_frame, image=self.logo_image, bd=0, highlightthickness=0)
self.logo_image_label.place(relx=0.5, rely=0.2, anchor="center")

def zeige_erste_seite(self):
# Alles im Haupt frame löschen
for widget in self.main_frame.winfo_children():
widget.destroy()

# Erstelle ein Objekt der Klasse für die erste Seite
FirstPage(self.main_frame)

def zeige_zweite_seite(self):
# Alles im Haupt frame löschen
for widget in self.main_frame.winfo_children():
widget.destroy()

# Erstelle ein Objekt der Klasse für die zweite Seite
SecondPage(self.main_frame)

def main():
root = tk.Tk()
app = Hauptfenster(root)
root.mainloop()

if name == "main": main()



first_page.py
import tkinter as tk

from Main_Menu import Hauptfenster

class FirstPage(tk.Frame):
def init(self, parent):
self.parent = parent
self.frame = tk.Frame(self.parent)
self.frame.pack(expand=True, fill='both')

# Neuen Inhalt für die zweite Seite hinzufügen
label = tk.Label(self.frame, text="Das ist die erste Seite")
label.pack()

# Button zum Hauptmenü hinzufügen
self.back_to_main_button = tk.Button(self.frame, text="Zurück zum Hauptmenü", command=self.back_to_main)
self.back_to_main_button.pack()

def back_to_main(self):
# Alles im Frame löschen
for widget in self.frame.winfo_children():
widget.destroy()

# Erstelle ein Objekt der Klasse für das Hauptmenü
Hauptfenster(self.parent)



I wanted to switch between those two while they are on separate files.
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • Predicting on new data using locally weighted regression (LOESS/LOWESS)How to fit a locally weighted regression in python so that it can be used to predict on new data? There is statsmodels.nonparametric.smoothers_lowe… Read More
  • After upgrade to V11 from V10, all routes disappeared and no images are shownHi, as i wrote in the title, after upgraded to V11, all my routes disappeared and no images are shown. It seems like the framework cannot get the r… Read More
  • Different types of Integer division in PythonIn terms of the resulting value (ignoring the resulting data type), are the following the same in Python if x and y are both numbers? int(x / y) x //… Read More
  • Audit services?I’ve built a medium sized Laravel app and was wondering if there are any companies/people I can hire to audit my code and give feedback and help me to… Read More
  • possible to delete a mongodb catch blockI have updated my mongodb driver which forces me to use two completion blocks: .then() .catch() instead of a single callback. The consequence of this … Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Features CodeIgniter
    Features CodeIgniter There is a great demand for the CodeIgniter framework in PHP developers because of its features and multiple advan...
  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • Laravel Breeze with PrimeVue v4
    This is an follow up to my previous post about a "starter kit" I created with Laravel and PrimeVue components. The project has b...
  • Fast Excel Package for Laravel
      Fast Excel is a Laravel package for importing and exporting spreadsheets. It provides an elegant wrapper around Spout —a PHP package to ...
  • Send message via CANBus
    After some years developing for mobile devices, I've started developing for embedded devices, and I'm finding a new problem now. Th...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • Larallow is a Permissions Package With Support for Scopes - 6/17/2025
  • Laravel Nightwatch - Deep monitoring & insights, no matter where you deploy. - 6/17/2025
  • Filament v4 Beta - Feature Overview - 6/16/2025
  • AnyCable Laravel Broadcaster - 6/16/2025
  • Parse Localized Numbers with Laravel's Number Class - 6/16/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda