Code – die besten Beiträge

Wieso zeigt Python das Bild nicht richtig an?

Hallo,

ich bin mal wieder auf ein Problem gestoßen, dass ich mit Google wohl einfach nicht lösen kann...
Folgendes sind die von mir importierten Module:

from tkinter import *
from tkinter.filedialog import askopenfilename
from threading import Thread
from PIL import Image, ImageTk
import cv2
import threading
import os
import time
import pickle

Und ein Ausschnitt des Codes meines Video Editors:

global Medien_Importierungen, Maximale_Breite, Maximale_Höhe
Videopfad = askopenfilename(filetypes =[('Video Files', '*.mp4')])
Geladenes_Video = cv2.VideoCapture(Videopfad)
Rückgabe, Einzelbild = Geladenes_Video.read()
if Einzelbild.shape[0] / Maximale_Höhe > Einzelbild.shape[1] / Maximale_Breite:
    height = Maximale_Höhe
    width = int(Einzelbild.shape[1] * height / Einzelbild.shape[0])
else:
    width = Maximale_Breite
    height = int(Einzelbild.shape[0] * width / Einzelbild.shape[1])
Einzelbild = cv2.resize(Einzelbild, (width, height))
Tkinter_Bild = ImageTk.PhotoImage(image=Image.fromarray(cv2.cvtColor(Einzelbild, cv2.COLOR_BGR2RGB)))
Thumbnail = Label(Medien, image = Tkinter_Bild)
if Medien_Importierungen % 2 == 0:
    Thumbnail.place(x = Fenster.winfo_screenwidth() * 0.01, y = Fenster.winfo_screenheight() / 10 + (Fenster.winfo_screenwidth() * 0.01 + Maximale_Höhe) * (int(Medien_Importierungen / 2)))
else:
    Thumbnail.place(x = Fenster.winfo_screenwidth() * 0.11, y = Fenster.winfo_screenheight() / 10 + (Fenster.winfo_screenwidth() * 0.01 + Maximale_Höhe) * (int(Medien_Importierungen / 2)))
Medien_Importierungen += 1   

Statt einem Bild wird jetzt nur ein weißes Bild angezeigt. Durch das verdoppeln der Zeile, in der ich die Funktion

Geladenes_Video.read()

angewendet habe, wurde auch nichts gelöst...

Bitte helft mir...

Alex

programmieren, Code, Programmiersprache, Python, Python 3, Tkinter

Customtkinter?

Ist es normal dass das erstellen von Labels, Textfelder oder Buttons in Klassen als Vorlage super viel Schreibarbeit ist oder geht das auch eleganter und sauberer?

main:

maclass Main(ctk.CTk):
    def __init__(self):
        super().__init__()
        self.main_window()
        self.chatbot_output = InputBox(self, 1, 1, 10, 10, "s", 500, 500, "#202222", "red", "white", "Gib einen Text ein...")
        self.chatbot_output.grid(row=1, column=1, pady=10, padx=10, sticky="s")
        self.chatbot_input = InputBox(self, 2, 1, 0, 10, "n", 500, 50, "#202222", "red", "white", "Gib einen Text ein...")
        self.chatbot_input.grid(row=2, column=1, pady=0, padx=10, sticky="n")
        self.placeholder = Label(self, 0, 1, 0, 10, "n", 500, 320, "transparent", "transparent", "white", ".")
        self.placeholder.grid(row=0, column=1, pady=0, padx=10, sticky="n")
    def main_window(self):
        height = 920
        width = 1680
        x = (self.winfo_screenwidth()//2)-(width//2)
        y = (self.winfo_screenheight()//2) - (height//2)
        self.geometry(f"{width}x{height}+{x}+{y}")
        self.title("YourTerminal")
        self.grid_columnconfigure(0, weight=0)
        self.grid_rowconfigure(0, weight=0)



if __name__ == "__main__":
    main = Main()
    main.mainloop()
    sys.exit()

Vorlage in einer Klasse und in einer anderen Datei:

class InputBox(ctk.CTkFrame):
    def __init__(self, master, row, column, pady, padx, sticky, width, height, entry_fg_color,frame_fg_color, textcolor, placeholder, *args, **kwargs):
        super().__init__(master, fg_color=frame_fg_color, *args, **kwargs)
        self.set_setup(row, column, pady, padx, sticky, width, height, entry_fg_color, textcolor, placeholder)

    def set_setup(self, row, column, pady, padx, sticky, width, height, entry_fg_color, textcolor, placeholder):
        self.input = ctk.CTkEntry(self,
                                  width=width,
                                  height=height,
                                  fg_color=entry_fg_color,
                                  text_color=textcolor,
                                  placeholder_text=placeholder,
                                  )
        self.input.grid(row=row, column=column, pady=pady, padx=padx, sticky=sticky)
Code, Programmiersprache, Python, Python 3, Tkinter, Pycharm

Meistgelesene Beiträge zum Thema Code