Tkinter mehrere Frames

Fragen zu Tkinter.
Antworten
tobi_ebers
User
Beiträge: 2
Registriert: Montag 21. November 2022, 14:36

Guten Tag,
und zwar habe ich folgendes Problem:
Ich bin jetzt seit ca. 2 Jahren mit python vertraut und kann auch die meisten grundlegenden Sachen. Nun wollte ich mich an eine grafische Benutzeroberfläche wagen. Da mir die custom tkinter oberfläche sehr gut gefallen hat habe ich damit ein Window erstellt und zwei Frames. ein frame links in dem die Buttons enthalten sind und ein Frame rechts. Nun sitze ich schon seit Tagen vor dem Problem wie ich den Frame rechts austaschen kann. Also ich drücke den Button links und das dazugehörige Fenster öffnet sich. kann mir dort vielleicht jemand helfen ich habe leider auch gar keinen Ansatz wie und wo ich anfangen soll.

import tkinter
import tkinter as tk
from tkinter import ttk
import customtkinter




customtkinter.set_default_color_theme("dark-blue") # Themes: "blue" (standard), "green", "dark-blue"


class MainWindow(customtkinter.CTk):

WIDTH = 780
HEIGHT = 520

def __init__(self):
super().__init__()
self.title("Trader backtest")
self.geometry(f"{MainWindow.WIDTH}x{MainWindow.HEIGHT}")
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed


# ============ create first frames ============

# configure grid layout (2x1)
self.grid_columnconfigure(1, weight=1)
self.grid_rowconfigure(0, weight=1)

self.frame_left = customtkinter.CTkFrame(master=self,
width=180,
corner_radius=0)
self.frame_left.grid(row=0, column=0, sticky="nswe")

self.frame_right = customtkinter.CTkFrame(master=self)
self.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)

# ============ frame_left ============

# configure grid layout (1x11)
self.frame_left.grid_rowconfigure(0, minsize=10) # empty row with minsize as spacing
self.frame_left.grid_rowconfigure(7, weight=1) # empty row as spacing
self.frame_left.grid_rowconfigure(8, minsize=20) # empty row with minsize as spacing
self.frame_left.grid_rowconfigure(11, minsize=10) # empty row with minsize as spacing

self.label_1 = customtkinter.CTkLabel(master=self.frame_left,
text="Trader Backtest",
text_font=("Roboto Medium", -16)) # font name and size in px
self.label_1.grid(row=1, column=0, pady=10, padx=10)

self.button_1 = customtkinter.CTkButton(master=self.frame_left,
text="Backtest",
command=self.button_event_backtest)
self.button_1.grid(row=2, column=0, pady=10, padx=20)

self.button_2 = customtkinter.CTkButton(master=self.frame_left,
text="Winrate",
command=self.button_event_winrate)
self.button_2.grid(row=3, column=0, pady=10, padx=20)

self.button_3 = customtkinter.CTkButton(master=self.frame_left,
text="Trade",
command=self.button_event_trade)
self.button_3.grid(row=4, column=0, pady=10, padx=20)

self.button_4 = customtkinter.CTkButton(master=self.frame_left,
text="Bot",
command=self.button_event_bot)
self.button_4.grid(row=5, column=0, pady=10, padx=20)

self.button_5 = customtkinter.CTkButton(master=self.frame_left,
text="Hold",
command=self.button_event_hold)
self.button_5.grid(row=6, column=0, pady=10, padx=20)





self.label_mode = customtkinter.CTkLabel(master=self.frame_left, text="Theme")
self.label_mode.grid(row=9, column=0, pady=0, padx=20, sticky="w")

self.optionmenu_1 = customtkinter.CTkOptionMenu(master=self.frame_left,
values=["Light", "Dark"],
command=self.change_appearance_mode)
self.optionmenu_1.grid(row=10, column=0, pady=10, padx=20, sticky="w")

# ============ frame_right ============

# configure grid layout (3x7)
self.frame_right.rowconfigure((0, 1, 2, 3), weight=1)
self.frame_right.rowconfigure(7, weight=10)
self.frame_right.columnconfigure((0, 1), weight=1)
self.frame_right.columnconfigure(2, weight=0)

self.frame_info = customtkinter.CTkFrame(master=self.frame_right)
self.frame_info.grid(row=0, column=0, columnspan=2, rowspan=4, pady=20, padx=20, sticky="nsew")

# ============ frame_info ============

# configure grid layout (1x1)
self.frame_info.rowconfigure(0, weight=1)
self.frame_info.columnconfigure(0, weight=1)



def button_event_backtest(self):
print("Backtest pressed")

def button_event_winrate(self):
print("Winrate pressed")

def button_event_trade(self):
print("trade pressed")

def button_event_bot(self):
print("Bot pressed")

def button_event_hold(self):
print("Hold pressed")

def button_event(self):
print("Button pressed")

def change_appearance_mode(self, new_appearance_mode):
customtkinter.set_appearance_mode(new_appearance_mode)

def on_closing(self, event=0):
self.destroy()





if __name__ == "__main__":
app = MainWindow()
app.mainloop()
tobi_ebers
User
Beiträge: 2
Registriert: Montag 21. November 2022, 14:36

Hat sich alles geklärt
Antworten