Variablen über Tkinter Frames weitergeben
Verfasst: Samstag 11. April 2020, 10:17
Hallo zusammen!
Ich bin ein kleiner Hobbyprogrammierer und hatte vor, mir ein kleines Tool zu schreiben, welches Commands in der Powershell ausführt.
Und jetzt meine kleine Frage: Wie kann ich Werte zwischen den verschiedenen Tkinter-Frames übergeben? (Ich möchte von Configurewindow die Eingabe von Path in die 2 Funktionen namens "convtom4a/convtomp4" übergeben)
Ich hab schon gegooglet, konnte aber keine Antwort finden, die ich nutzen könnte.
Den Code findet ihr hier:
Ich freue mich über jede Antwort ^^
MFG
D3us3x
Ich bin ein kleiner Hobbyprogrammierer und hatte vor, mir ein kleines Tool zu schreiben, welches Commands in der Powershell ausführt.
Und jetzt meine kleine Frage: Wie kann ich Werte zwischen den verschiedenen Tkinter-Frames übergeben? (Ich möchte von Configurewindow die Eingabe von Path in die 2 Funktionen namens "convtom4a/convtomp4" übergeben)
Ich hab schon gegooglet, konnte aber keine Antwort finden, die ich nutzen könnte.
Den Code findet ihr hier:
Code: Alles auswählen
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
import os
def CallConfigureWindow():
ConfigureWindow = Tk()
folder_path = "/Downloads/%(title)s.%(ext)s"
ConfigureWindow.title("Configuration")
ConfigureWindow.minsize(430, 110)
ConfigureWindow.maxsize(430, 110)
ConfigureWindow.lift()
Label(ConfigureWindow, text="Download Path:", font="Arial 16") .grid(row=0, column=0, sticky=W, pady=5, padx=5)
Path = Entry(ConfigureWindow, width=60)
def selectFolder():
root = Tk()
root.attributes("-topmost", True)
root.withdraw()
folder_path = filedialog.askdirectory()
Path.delete(first=0,last=100)
Path.insert(10, folder_path)
Path.insert(10, "/%(title)s.%(ext)s")
ConfigureWindow.lift()
return folder_path
def clearPath():
Path.delete(first=0,last=22)
Path.insert(10, "/Downloads/%(title)s.%(ext)s")
Path.insert(10, folder_path)
Path.grid(row=1, column=0, sticky=W, pady=5, padx=2)
Button(ConfigureWindow, text="Browse", command=selectFolder) .grid(row=1, column=1, sticky=W, pady=5, padx=5)
Button(ConfigureWindow, text="Reset Settings", width=18, command=clearPath) .grid(row=2, column=0, sticky=W, pady=5, padx=5)
ConfigureWindow.mainloop( )
return folder_path
def main():
MainWindow = Tk()
MainWindow.title("YouTube Converter")
MainWindow.minsize(500, 120)
MainWindow.maxsize(500, 120)
Label(MainWindow, text="Link:", font="Arial 22") .grid(row=0, column=0, sticky=W, pady=5, padx=5)
Link = Entry(MainWindow, width=80)
Link.grid(row=1, column=0, pady=5, padx=5)
def convtom4a():
command=os.system('powershell -command youtube-dl ' + Link.get() + " -f m4a -o " + )
def convtomp4():
command=os.system('powershell -command youtube-dl ' + Link.get() + " -f mp4 -o " + )
Button(MainWindow, text="Configure", command=CallConfigureWindow) .grid(row=2, column=0, sticky=W, pady=5, padx=5)
Button(MainWindow, text="Convert to Video", command=convtomp4) .grid(row=2, column=0, sticky=E, pady=5, padx=120)
Button(MainWindow, text="Convert to Audio", command=convtom4a) .grid(row=2, column=0, sticky=E, pady=5, padx=5)
def on_closing():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
MainWindow.destroy()
MainWindow.protocol("WM_DELETE_WINDOW", on_closing)
MainWindow.mainloop( )
if __name__ == "__main__":
main()
MFG
D3us3x