'How can I create multiple pages in customtkinter?
It always gives me some error because of the different frames... I can't figure out, why it is not allowing me to create multiple frames. I tried to create multiple frames, but it just doesnt work...
Error:
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
TypeError: create() argument 1 must be str or None, not type
import tkinter.messagebox
from types import new_class
import customtkinter
import random
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
class Bitmine(tkinter.Tk):
def __init__(self, *args, **kwargs):
tkinter.Tk.__init__(self, *args, **kwargs)
container = tkinter.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (Home, Mining):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(Home)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class Home(customtkinter.CTk):
WIDTH = 780
HEIGHT = 520
def __init__(home, controller):
super().__init__()
home.controller = controller
home.title("BitMine™ v3")
home.geometry(f"{1000}x{700}")
# home.minsize(App.WIDTH, App.HEIGHT)
home.protocol("WM_DELETE_WINDOW", home.on_closing) # call .on_closing() when app gets closed
# ============ create two frames ============
# configure grid layout (2x1)
home.grid_columnconfigure(1, weight=1)
home.grid_rowconfigure(0, weight=1)
home.frame_left = customtkinter.CTkFrame(master=home,
width=180,
corner_radius=0)
home.frame_left.grid(row=0, column=0, sticky="nswe")
home.frame_right = customtkinter.CTkFrame(master=home)
home.frame_right.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)
# ============ frame_left ============
# configure grid layout (1x11)
home.frame_left.grid_rowconfigure(0, minsize=10) # empty row with minsize as spacing
home.frame_left.grid_rowconfigure(6, weight=1) # empty row as spacing
home.frame_left.grid_rowconfigure(8, minsize=20) # empty row with minsize as spacing
home.frame_left.grid_rowconfigure(11, minsize=10) # empty row with minsize as spacing
home.label_1 = customtkinter.CTkLabel(master=home.frame_left,
text="BitMine™ ",
text_font=("Roboto", -24)) # font name and size in px
home.label_1.grid(row=1, column=0, pady=10, padx=10)
home.button_1 = customtkinter.CTkButton(master=home.frame_left,
text="⛏ Mining",
fg_color=("gray75", "gray30"),
command=lambda: controller.show_frame("Mining"))
home.button_1.grid(row=2, column=0, pady=10, padx=20)
home.button_2 = customtkinter.CTkButton(master=home.frame_left,
text="⚙️ Settings",
fg_color=("gray75", "gray30"), # <- custom tuple-color
command=home.button_event)
home.button_2.grid(row=3, column=0, pady=10, padx=20)
home.button_3 = customtkinter.CTkButton(master=home.frame_left,
text="❌ Exit",
fg_color=("gray75", "gray30"), # <- custom tuple-color
command=home.button_event)
home.button_3.grid(row=4, column=0, pady=10, padx=20)
home.switch_2 = customtkinter.CTkSwitch(master=home.frame_left,
text="Dark Mode",
command=home.change_mode)
home.switch_2.grid(row=10, column=0, pady=10, padx=20, sticky="w")
# ============ frame_right ============
# configure grid layout (3x7)
home.frame_right.rowconfigure((0,1,2,3,4,5), weight=0)
home.frame_right.rowconfigure((6,7), weight=0)
home.frame_right.columnconfigure((0, 1), weight=1)
home.frame_right.columnconfigure(2, weight=1)
home.frame_right.columnconfigure((3), weight=1)
home.frame_info = customtkinter.CTkFrame(master=home.frame_right)
home.frame_info.grid(row=0, column=0, columnspan=4, rowspan=3, pady=20, padx=20, sticky="nsew")
# ============ frame_info ============
# configure grid layout (1x1)
home.frame_info.rowconfigure((2),weight=0)
home.frame_info.columnconfigure(0, weight=1)
home.label_info_1 = customtkinter.CTkLabel(master=home.frame_info,
text="Test",
height=200,
text_font=("Roboto", -16),
fg_color=("white", "gray38"), # <- custom tuple-color
justify=tkinter.LEFT)
home.label_info_1.grid(column=0, row=2, columnspan=4, sticky="nswe", padx=20, pady=20)
randint = random.randint(45, 94)
activeminer = str(randint)
serverload = int(activeminer)/100
print(serverload)
home.label_progressbar = customtkinter.CTkLabel(master=home.frame_info,
text="Active Miners: " + activeminer,
fg_color=None,
text_font=("", -16))
home.label_progressbar.grid(row=0, column=0, columnspan=1, pady=10, padx=15, sticky="nw")
home.progressbar = customtkinter.CTkProgressBar(master=home.frame_info
)
home.progressbar.grid(row=1, column=0, columnspan=4, sticky="we", padx=20, pady=5)
# ============ frame_right ============
home.label_slider = customtkinter.CTkLabel(master=home.frame_info,
text="Hash Rate: ",
fg_color=None,
text_font=("", -16))
home.label_slider.grid(row=3, column=0, columnspan=1, pady=10, padx=15, sticky="nw")
home.slider_2 = customtkinter.CTkSlider(master=home.frame_info,
from_=1,
to=3,
number_of_steps=3
)
home.slider_2.grid(row=4, column=0, columnspan=4, pady=20, padx=20, sticky="we")
radio_var1 = tkinter.IntVar(0)
radio_var2 = tkinter.IntVar(0)
def radiobutton1_event():
crypto = radio_var1.get()
if crypto == 1:
btceth = "Bitcoin"
else:
btceth = "Ethereum"
print("Crypto:", btceth)
def radiobutton2_event():
miningm = radio_var2.get()
if miningm == 1:
prvpub = "Public Mining"
else:
prvpub = "Private Mining"
print("Mining:", prvpub)
private = home.radio_button_1 = customtkinter.CTkRadioButton(master=home.frame_right, text="Bitcoin",
command=radiobutton1_event, variable= radio_var1, value=1)
home.radio_button_1.grid(row=6, column=1,columnspan=1, pady=20, padx=20, sticky="nswe")
private = home.radio_button_1 = customtkinter.CTkRadioButton(master=home.frame_right, text="Ethereum",
command=radiobutton1_event, variable= radio_var1, value=0)
home.radio_button_1.grid(row=7, column=1,columnspan=1, pady=20, padx=20, sticky="nswe")
metod = home.radio_button_2 = customtkinter.CTkRadioButton(master=home.frame_right, text="Private Mining",
command=radiobutton2_event, variable= radio_var2, value=1)
home.radio_button_2.grid(row=6, column=3,columnspan=1, pady=20, padx=20, sticky="nswe")
method = home.radio_button_2 = customtkinter.CTkRadioButton(master=home.frame_right, text="Public Mining",
command=radiobutton2_event, variable= radio_var2, value=0)
home.radio_button_2.grid(row=7, column=3,columnspan=1, pady=20, padx=20, sticky="nswe")
home.entry = customtkinter.CTkEntry(master=home.frame_right,
width=120,
placeholder_text="Wallet Adress:")
home.entry.grid(row=8, column=0, columnspan=3, pady=20, padx=20, sticky="we")
home.button_5 = customtkinter.CTkButton(master=home.frame_right,
text="Set Wallet",
command=home.button_event)
home.button_5.grid(row=8, column=3, columnspan=1, pady=20, padx=20, sticky="we")
# set default values
home.radio_button_1.select()
home.radio_button_2.select()
home.radio_button_1.select()
home.radio_button_2.select()
home.switch_2.select()
home.slider_2.set(0.7)
home.progressbar.set(serverload)
def button_event(home):
print("Button pressed")
def change_mode(home):
if home.switch_2.get() == 1:
customtkinter.set_appearance_mode("dark")
else:
customtkinter.set_appearance_mode("light")
def on_closing(home, event=0):
home.destroy()
def start(home):
home.mainloop()
class Mining(customtkinter.CTk):
def __init__(home):
super().__init__()
if __name__ == "__main__":
app = Bitmine(Home)
app.start()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
