Im taking a crack at building me a fun little personal "Do Stuff" App.
I put in a VideoDownloader, ImageEditor, FontChooser, ColorChooser, DateChooser, TextBox, ThemedComboBox and put them all in a ttkbootstrap Notebook.
Everything worked!
But after I added the "App" into a "Login Window" that destroys itself and runs the "App" if you enter the correct Passwd, the App started closing everything I try to run certain features.
It runs the Login window fine, takes the passwd and runs the "App" with no issues. Buts once in the App, It acts funny.
I can still download a video fine, I can run the "Image Editor" fine. But when I click on the FontChooser, ColorChooser in TAB3 or The CalendarChooser and ComboBox in TAB4 the App closes all together.
It only seems to close the App when I interact with something that tries to open a separate window. Like the FontDialogChooser, ColorChooserDialog, ComboBox.
Any Ideas on why this is happening and how to fix it?
MacOS Big Sur 11.17.10
Also, getting this ERROR when the LOGIN accepts the PASSWD and the App Window opens:
in _add_scroll_binding if "<MouseWheel>" not in bindings: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument of type 'NoneType' is not iterable
Not sure its related to my issue or another thing to fix. What do you think?
Heres my Code for your observation. (Also, if theres a better way to share code on here, please let me know.
Heres my Code: (also, if theres a better way to post code here. Please let me know)
-Passwd to Login Window is: Luna1120 no username required.
from tkinter import *
from ttkbootstrap.constants import *
import ttkbootstrap as tb
from datetime import date
from ttkbootstrap.dialogs import Querybox
from PIL import Image, ImageTk
Image.CUBIC = Image.BICUBIC
import tkinter
import customtkinter
from pytube import YouTube
from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog
from ttkbootstrap.scrolled import ScrolledFrame
from ttkbootstrap.toast import ToastNotification
from ttkbootstrap.dialogs import FontDialog
from PIL import Image, ImageEnhance, ImageFilter
import os
import webbrowser as wb
###%$%$%$%$%$%$%$%$%$%$%$%$%$%$%%%$
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
appMain = customtkinter.CTk() #CTK Window
appMain.geometry("600x440")
appMain.title("Login")
def button_function():
if passwd_entry.get() == "Luna1120":
appMain.destroy()
#root = Tk()
root = tb.Window(themename="solar")
root.title("BootStrap Bill")
root.iconbitmap("images/codemy.ico")
root.geometry("650x800")
#### NOTEBOOK
my_notebook = tb.Notebook(root,
bootstyle="default",
)
my_notebook.pack(pady=10)
tab1 = tb.Frame(my_notebook)
tab2 = tb.Frame(my_notebook)
tab3 = tb.Frame(my_notebook)
tab4 = tb.Frame(my_notebook)
tab5 = tb.Frame(my_notebook)
sf = ScrolledFrame(tab1, height=600, bootstyle="default")
sf.pack(fill=BOTH, expand=YES, pady=10, padx=10)
##################### Start TAB1
## Download a Tube, Dude
def startDownload():
try:
ytLink = link.get()
ytObject = YouTube(ytLink, on_progress_callback=on_progress)
video = ytObject.streams.get_highest_resolution()
title.configure(text=ytObject.title, text_color="white")
finishlabel.configure()
video.download()
finishlabel.configure(text="- Good Dog -", text_color="lightblue")
toast.show_toast()
except:
finishlabel.configure(text="- Bad Dog -",
text_color="red"
)
link.configure(state="disabled")
#toast_naw.show_toast()
if finishlabel == "- Good Dog -":
toast.show_toast()
def clear():
link.configure(state="normal")
link.delete(0, END)
title.configure(text="")
finishlabel.configure(text="-What's beneath the Couch?-", text_color="white")
my_meter.configure(amountused=0)
pPercentage.configure(text="0%")
link.configure(placeholder_text="Please, Curb Your URL...")
####TOAST MESSAGEs
toast = ToastNotification(title="ClydeTUBE Message",
bootstyle="dark",
message= "YOUR FILE WAS FETCHED",
duration=5000,
alert=True,
position=(20, 20, 'ne'),
icon="CTM",
iconfont=("bradley hand", 5)
)
toast_naw = ToastNotification(title="ClydeTUBE Message",
bootstyle="warning",
message= "DIG ERROR: File Not Found",
duration=5000,
alert=True,
position=(20, 20, 'ne'),
icon="CTM",
iconfont=("bradley hand", 5)
)
#system
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
# App Label
title1 = customtkinter.CTkLabel(sf,
text="ClydeTUBE",
font=("hanzipen sc",50),
text_color="white"
)
title1.pack(padx=10, pady=25)
# Entry/link input
url_var = tkinter.StringVar()
link = customtkinter.CTkEntry(sf,
width=350,
height=30,
placeholder_text="Please, Curb your URL...",
font=("bradley hand", 16),
border_color="white",
corner_radius=50,
fg_color=("blue", "lightblue"),
placeholder_text_color="black",
text_color="black",
)
link.pack(pady=1)
# Finished Downloading
finishlabel = customtkinter.CTkLabel(sf,
text="-What's beneath the Couch?-",
font=("heiti sc", 13),
text_color="lightblue"
)
finishlabel.pack()
## "search" label
title = customtkinter.CTkLabel(sf,
text="",
font=("muna", 16),
text_color="white")
title.pack()
# progress bar
def on_progress(stream, chunk, bytes_remaining):
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
percentage_of_completion = bytes_downloaded / total_size * 100
per = str(int(percentage_of_completion))
#pPercentage.configure(text=per + '%')
pPercentage.update()
# update meter
my_meter.configure(amountused=int(percentage_of_completion))
# Profress Percentage
#### Meter
my_meter = tb.Meter(sf,
bootstyle="light",
subtext="Complete",
interactive=False,
textright="%",
#textleft="$",
metertype='semi',
stripethickness=10,
metersize=222,
amountused=0,
amounttotal=100,
#subtextfont=("muna", 10),
subtextstyle="light",
textfont=("bradley hand", 22),
meterthickness=5,
#wedgesize=5,
#arcrange=200,
#stepsize=20,
)
my_meter.pack(pady=1)
pPercentage = customtkinter.CTkLabel(sf, text="")
pPercentage.pack()
#add button
download = customtkinter.CTkButton(sf, text="- Fetch -",
font=("bradley hand", 25),
text_color="black",
height=40,
width=150,
fg_color="white",
command=startDownload,
border_width=2.5,
border_color="lightblue",
corner_radius=50,
hover_color="grey")
download.pack(padx=10, pady=10)
#CLEAR BUTTON
clear_button = customtkinter.CTkButton(sf,
text="Clear",
font=("muna", 12),
command=clear,
text_color="black",
corner_radius=5,
border_color="black",
width=60,
height=17,
fg_color="grey",
hover_color="black",
)
clear_button.pack(pady=12)
######TREEVIEW
#define columns
columns = ("first_name", "last_name", "email")
#create treeview
my_tree = tb.Treeview(sf,
bootstyle="default",
columns=columns,
show="headings",
)
my_tree.pack(pady=10)
#define headings
my_tree.heading("first_name", text="First Name")
my_tree.heading("last_name", text="Last Name")
my_tree.heading("email", text="Email Address")
#create sample data
contacts = []
for n in range(1,20):
contacts.append((f"First {n}", f"Last {n}", f"Email {n}@address.com"))
#add data to treeview
for contact in contacts:
my_tree.insert("", END, values=contact)
######END TREEVIEW
################# END OF TAB1
############# Start TAB2
#IMAGE EDITOR
########EDITOR LOGIC#########
path = './imgs'
pathout = '/editedImgs'
def submit_edit():
for filename in os.listdir(path):
img = Image.open(f"{path}/{filename}")
edit = img.filter(ImageFilter.SHARPEN).convert ("L").rotate(0)
factor = 1.5
enhancer = ImageEnhance.Contrast(edit)
edit = enhancer.enhance(factor)
clean_name = os.path.splitext(filename)[0]
edit.save(f'.{pathout}/{clean_name}_edited.jpg')
#END OF EDITOR LOGIC ###################
######Image Edit Button
edit_button = customtkinter.CTkButton(tab2,
text="Edit!",
font=("bradley hand", 20),
text_color="black",
command=submit_edit,
width=200,
height=40,
corner_radius=30,
bg_color="transparent",
fg_color="lightblue",
border_width=1.5,
border_color="black",
hover_color="white",
)
edit_button.pack(pady=60)
##################END OF TAB2
################## Start of TAB3 #
####Color Chooser Dialog #######
def color_click():
#create chooser
color_chooser = ColorChooserDialog()
#show chooser
color_chooser.show()
#return color info
colors = color_chooser.result
#output to label .HEX, .HSL, .RGB
color_label.config(text=colors.hex)
#color_label.config(text=colors.hel)
#color_label.config(text=colors.rgd)
#change bg Color to color_choice
color_label.configure(foreground=colors.hex)
color_label = tb.Label(tab3, text="", font=("muna", 25))
color_label.pack(pady=20)
color_button = tb.Button(tab3, text="Grab Color Info", bootstyle="secondary", command=color_click)
color_button.pack(pady=20)
####END OF COLOR CHOOSER
######FONT PICKER
def open_font():
#define dialog
fd = FontDialog()
#show dialog
fd.show()
#capture result and update label
font_label.config(font=fd.result)
font_button = tb.Button(tab3, bootstyle="secondary", text="Get Font Log", command=open_font)
font_button.pack(pady=20)
font_label = tb.Label(tab3, text="This is not the end of the World. Dont Panic!!")
font_label.pack(pady=10)
########End of Font Picker
################# Start TAB3
#
#
################ End of TAB3
#################Start TAB4
#
#
#########End of TAB4
################Start of TAB5
#######TEXTBOX
my_label = Label(tab5, text="Text Box", font=("bradley hand", 15))
my_label.pack(pady=10)
text_box1 = Text(tab5, width=70, height=10)
text_box1.pack(pady=10)
#######END OF TEXTBOX
################## End of TAB5
#add frames/tabs to the notebook
my_notebook.add(tab1, text="ClydeTUBE")
my_notebook.add(tab2, text="Image Editor")
my_notebook.add(tab3, text="Color's & Font's")
my_notebook.add(tab4, text="Calender")
my_notebook.add(tab5, text="TextBox")
######## Thank You Label
dl_label = tb.Label(text="-Thank You-", bootstyle="primary")
dl_label.pack(pady=10)
root.mainloop()
else:
appMain.destroy()
w2=customtkinter.CTk()
w2.geometry("1280x720")
w2.title("ERROR: 504")
l1=customtkinter.CTkLabel(master=w2, text="Wrong Password!!!", font=("Century Gothic", 60), text_color="red")
l1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
reset_button=customtkinter.CTkButton(master=w2,
font=("Century Gothic", 15),
text="Try Again",
fg_color="lightblue",
border_color="black",
border_width=1,
text_color="black"
)
reset_button.place(relx=0.5, rely=0.6, anchor=tkinter.CENTER)
w2.mainloop()
###### LOGIN WINDOW BITS #######
#BG_Image for Login Frame
img1=ImageTk.PhotoImage(Image.open("peace.jpg"), Image.Resampling.LANCZOS)
l1=customtkinter.CTkLabel(master=appMain, image=img1)
l1.pack()
Logframe = customtkinter.CTkFrame(master=l1, width=320, height=360, corner_radius=15)
Logframe.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
l2 = customtkinter.CTkLabel(master=Logframe,
text="Log in to Continue, Please.",
font=("century gothic", 20))
l2.place(x=10,y=45)
#Username Entry
name_entry = customtkinter.CTkEntry(master=Logframe,
placeholder_text="User",
width=220,
height=30,
border_width=2,
corner_radius=10,
)
name_entry.place(x=50,y=110)
# Passwd Entry
passwd_entry = customtkinter.CTkEntry(master=Logframe,
placeholder_text="Passwd",
show="*",
width=150,
height=30,
border_width=2,
corner_radius=10,
)
passwd_entry.place(x=50,y=165)
#"Forgot Passwd?" Label
l2 = customtkinter.CTkLabel(master=Logframe,
text="Forgot Password?",
font=("century gothic", 12))
l2.place(x=165,y=195)
#Login Button
button1 = customtkinter.CTkButton(master=Logframe,
text="Login",
font=("muna", 15),
fg_color="lightblue",
border_color="black",
text_color="black",
border_width=1.5,
hover_color="white",
corner_radius=6,
width=220,
command=button_function)
button1.place(x=50,y=240)
## Ween and Gmail buttons
#images for Ween and Gmail buttons
img3=customtkinter.CTkImage(Image.open("ween.webp").resize((20,20), Image.Resampling.LANCZOS))
img2=customtkinter.CTkImage(Image.open("gmail.png").resize((20,20), Image.Resampling.LANCZOS))
# Ween Button
def ween():
wb.open("https://ween.com/")
button2 = customtkinter.CTkButton(master=Logframe,
text="Ween",
image=img3,
corner_radius=6,
width=100,
height=20,
compound="left",
text_color="black",
fg_color="white",
command=ween)
button2.place(x=50,y=290)
#Gmail button
def gmail():
wb.open("https://mail.google.com/mail/u/0/#inbox")
button3 = customtkinter.CTkButton(master=Logframe,
text="GMail",
image=img2,
corner_radius=6,
width=100,
height=20,
compound="left",
text_color="black",
fg_color="white",
command=gmail)
button3.place(x=170,y=290)
appMain.mainloop()