I'm creating an application to download YouTube videos without payment using Python, and everything is working well in terms of creating the screen. However, to make it cleaner and more beautiful, I want to add an image to the download button. As mentioned in the title, the image will be blank. here is the code:
from pytube import YouTube
import tkinter as tk
from tkinter import ttk
class Screen:
def __init__(self, entry_widget, category_combobox):
self.entry = entry_widget
self.category_combobox = category_combobox
self.screen_instance = (self.entry, self.category_combobox)
def ErrorMessage(self,Message):
ErrorWd = ttk.Frame(master=window)
# Make the change in parameter of Download for which the user chose
def get_stream_by_category(self, selected_category, video):
category_to_itag = {
'mp4': 137,
'webm': 248,
'AudioOnly': 251,
}
itag = category_to_itag.get(selected_category, 'default')
if itag == 'default':
return video.streams.get_highest_resolution()
else:
return video.streams.get_by_itag(itag)
# Download the video, getting the URL and category selected in inputs by the user
def DownloadVideo(self):
url = self.entry.get()
selected_category = self.category_combobox.get()
video = YouTube(
url,
on_progress_callback=print("just there"),
on_complete_callback=print("Success!"),
proxies=None,
use_oauth=False,
allow_oauth_cache=True
)
stream = self.get_stream_by_category(selected_category, video)
stream.download()
self.entry.delete(0, 'end')
# This condition makes the variables in __init__ accessible for everyone
if __name__ == '__main__':
# Create the main window and specify some characteristics
window = tk.Tk()
window.title('SpoTube')
window.geometry('726x512')
window['background'] = '#242424'
# Make an instruction label for the user
def UserInstructionConstruct(window):
UserInstruction = ttk.Label(master=window, text='Insert a link to download!',
font='poppins 15 bold', background='#242424', foreground='white')
UserInstruction.pack(pady=20)
UserInstructionConstruct(window)
input_link = ttk.Frame(master=window)
entry = ttk.Entry(master=input_link)
categories = ["AudioOnly", "webm", "mp4"]
# Create a Combobox for selecting a category
category_var = tk.StringVar()
category_combobox = ttk.Combobox(input_link, values=categories, textvariable=category_var, state="readonly", width=5)
category_combobox.pack(side='bottom', pady=10)
screen_instance = Screen(entry, category_combobox)
def CreateDownloadButton():
# Load rounded button image
load_image = tk.PhotoImage(file="SpotTubeApp/BlackDownloadButton.png")
button = ttk.Button(master=input_link,width=5,image=load_image, command=screen_instance.DownloadVideo, compound="center")
button['style'] = 'RoundedButton.TButton'
button.pack(side='bottom', padx=5, pady=10)
CreateDownloadButton()
entry.pack(side='left', padx=10)
input_link.pack(pady=125)
# Configure a custom style for the rounded button
style = ttk.Style()
style.configure('RoundedButton.TButton', padding=10, relief="flat")
window.mainloop()
I tried change the image, change the paths, and try another images. I just want a way to make the buttons and inputs to look more like CSS flat design style. Sorry if my english or question isn't clear, I'm learning both, Lol.