Files
PiperTTS-scripts/Uptated-Prototype/PiperTTS-GUI-Test-2nd.py

113 lines
4.0 KiB
Python

import tkinter as tk
from tkinter import ttk
from tkinter import filedialog
import atexit
# Start of Code - Start of Tkinter loop
Root_Window = tk.Tk()
Root_Window.title("PiperTTS - Prototype GUI 2nd") # Sets the GUI Title
# Setting up Window Starting Size and Position (can only be even numbers)
Window_Width = 420
Window_Height = 580
# Getting Screen Width and Height
Screen_Width = Root_Window.winfo_screenwidth()
Screen_Height = Root_Window.winfo_screenheight()
# Calculate Center of Screen for the window
Window_PosX = (Screen_Width/2) - (Window_Width/2)
Window_PosY = (Screen_Height/2) - (Window_Height/2)
# Sets the GUI geometry and attempts to centers window on screen
Root_Window.geometry(f'{Window_Width}x{Window_Height}+{int(Window_PosX)}+{int(Window_PosY)}')
Root_Window.minsize(Window_Width, Window_Height)
# Attempts to create a Input Frame
try:
Input_Box_Frame = ttk.Frame(Root_Window)
except:
print("An exception occurred - when creating input Frame.")
# Attempts to create a Controls Frame
try:
Controls_Box_Frame = ttk.Frame(Root_Window)
except:
print("An exception occurred - when creating Controls Frame.")
# Attempts to Place Input and Controls frames
try:
Input_Box_Frame.place(x = 0, y = 0, relwidth = 1, relheight = 0.8)
Controls_Box_Frame.place(x = 0, rely = 0.8, relwidth = 1, relheight = 0.8)
except:
print("An exception occurred - when placing Frames.")
# Attempts to create a Input box
try:
Input_Box = tk.Text(Input_Box_Frame, selectbackground="yellow", selectforeground="black", undo=True)
Input_Box.pack(padx=5, pady=5, expand = True, fill = "both")
except:
print("An exception occurred - when creating input box.")
#
def PiperTTS_GUI_PlayAndPause():
try:
if GUI_Button_PlayAndPause["text"] == "":
GUI_Button_PlayAndPause["text"] = ""
else:
GUI_Button_PlayAndPause["text"] = ""
except:
print("An exception occurred - when pressing Play And Pause Button.")
# Creating Buttons
GUI_Button_PlayAndPause = ttk.Button(Controls_Box_Frame, text="", command=PiperTTS_GUI_PlayAndPause)
GUI_Button_Stop = ttk.Button(Controls_Box_Frame, text="")
GUI_Button_previous = ttk.Button(Controls_Box_Frame, text="")
GUI_Button_Next = ttk.Button(Controls_Box_Frame, text="")
# Creating a Test Text Label
My_Test_Label = ttk.Label(Controls_Box_Frame, text="Test Text?")
My_Test_Label.grid(row=1, column=0, columnspan=3)
# Aligning Buttons to grid
GUI_Button_PlayAndPause.grid(row=0, column=0)
GUI_Button_previous.grid(row=0, column=1)
GUI_Button_Stop.grid(row=0, column=2)
GUI_Button_Next.grid(row=0, column=3)
#Creating Toolbar menu
Root_Toolbar = tk.Menu(Root_Window)
Root_Window.configure(menu=Root_Toolbar)
#Creating File menu for Toolbar
File_Toolbar = tk.Menu(Root_Toolbar, tearoff=False)
Root_Toolbar.add_cascade(label="File", menu=File_Toolbar)
File_Toolbar.add_command(label="New")
File_Toolbar.add_command(label="Open")
File_Toolbar.add_command(label="Save as Wave")
File_Toolbar.add_separator()
File_Toolbar.add_command(label="Exit", command=Root_Window.quit)
#Creating Playback menu for Toolbar
Playback_Toolbar = tk.Menu(Root_Toolbar, tearoff=False)
Root_Toolbar.add_cascade(label="Playback", menu=Playback_Toolbar)
Playback_Toolbar.add_command(label="")
Playback_Toolbar.add_command(label="")
Playback_Toolbar.add_command(label="")
Playback_Toolbar.add_command(label="")
Playback_Toolbar.add_command(label="")
#Creating Tools menu for Toolbar
Tools_Toolbar = tk.Menu(Root_Toolbar, tearoff=False)
Root_Toolbar.add_cascade(label="Tools", menu=Tools_Toolbar)
Tools_Toolbar.add_command(label="Insert Selection")
Tools_Toolbar.add_command(label="Insert Clipboard")
Tools_Toolbar.add_separator()
Tools_Toolbar.add_command(label="Randomise Text")
Tools_Toolbar.add_command(label="Reverse Text")
Tools_Toolbar.add_separator()
Tools_Toolbar.add_command(label="Prefrences")
# End of Code - Emd of Tkinter loop
Root_Window.mainloop()
# Function called on Exit
def Registered_Exit():
print("Goodbye!?")
# Regestering Exit
atexit.register(Registered_Exit)