Wie erstelle ich eine CTKTEXTBOX automatisch, um seinen Inhalt in CustomTkinter zu passen?Python

Python-Programme
Anonymous
 Wie erstelle ich eine CTKTEXTBOX automatisch, um seinen Inhalt in CustomTkinter zu passen?

Post by Anonymous »

Ich verwende CustomTkinter , um eine Quiz -Schnittstelle zu erstellen. Jede Frage wird in einem ctkTextBox (LBL) angezeigt, und ich möchte, dass das Textfeld je nach Inhalt automatisch seine Höhe (y Dimension) anpasst.frames = []
for idx, (question, answers) in enumerate(questions):
frame = ctk.CTkFrame(frmcau, fg_color="white", corner_radius=10, border_width=2, border_color="#D3D3D3")
frame.pack(pady=15, padx=15, fill="x")
frame.grid_columnconfigure(0, weight=1, uniform=1)
frame.grid_rowconfigure(0, weight=1)

lbl = ctk.CTkTextbox(frame, wrap="word", font=("Arial", 16),
fg_color="white", text_color="black", border_width=0)
lbl.insert("1.0", f"Câu {idx+1}: {question}")
lbl.configure(state="disabled")
lbl.grid(row=0, column=0, sticky="nsew", pady=(5, 0), padx=10)

for ans_idx, ans in enumerate(answers):
ctk.CTkRadioButton(
frame,
text=ans,
variable=user_answers[idx],
value=ans_idx,
font=("Arial", 14),
text_color="black",
hover_color="#E0E0E0"
).grid(row=ans_idx + 1, column=0, sticky="we", pady=(0, 5), padx=10)

frames.append(frame)

< /code>
Gibt es eine zuverlässige Möglichkeit, eine ctktextbox automatische Höhe zu erstellen, basierend auf dem Text, den es enthält (mit Verpackung) in Pixel oder Zeilen, in einem dynamischen Layout, ...? < /p>
Ich bin offen für Workarounds, einschließlich zusätzlicher Bibliotheken.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post