我在将 tkinter 标签加入 GUI 时遇到问题。我试图将 asunto 标签放在 asunto 文本字段的左上角,虽然这已经实现了,但它们相距甚远。
预期的 GUI:
实际图形用户界面:
这是代码:
def show_personalizado_page():
hide_current_widgets()
root.current_page = "personalizado"
root.title("EvaMailer")
root.geometry("800x600")
# Add the logo
try:
logo_image = Image.open("EvaMailer.png") # Update with your logo path
logo_image = logo_image.resize((100, 100), Image.Resampling.LANCZOS) # Resize with proper resampling filter
logo = ImageTk.PhotoImage(logo_image)
logo_label = tk.Label(root, image=logo)
logo_label.image = logo # Keep a reference to avoid garbage collection
logo_label.grid(row=0, column=1, pady=10, columnspan=2)
except Exception as e:
print(f"Error loading image: {e}")
# Add the 'Regresar' button
def go_back():
show_main_page()
regresar_button = tk.Button(root, text="Regresar", command=go_back)
regresar_button.grid(row=0, column=0, padx=10, pady=10, sticky='w')
# Add the 'Columnas' listbox with a scrollbar
columns_frame = tk.Frame(root)
columns_frame.grid(row=1, column=0, padx=10, pady=10, sticky='ns', rowspan=2)
columns_label = tk.Label(columns_frame, text="Columnas", font=('Arial', 12, 'bold'))
columns_label.pack(anchor='w', padx=10)
columns_listbox = tk.Listbox(columns_frame, height=15)
columns_listbox.pack(side='left', fill='y')
columns_scrollbar = tk.Scrollbar(columns_frame, orient='vertical', command=columns_listbox.yview)
columns_scrollbar.pack(side='right', fill='y')
columns_listbox.config(yscrollcommand=columns_scrollbar.set)
# Add the 'Asunto' entry
subject_label = tk.Label(root, text="Asunto", font=('Arial', 12, 'bold'))
subject_label.grid(row=1, column=1, padx=10, pady=(10, 2), sticky='w')
subject_entry = tk.Entry(root, width=30) # Adjust width for a smaller entry
subject_entry.grid(row=2, column=1, padx=10, pady=(2, 10), sticky='ew')
# Add the 'Cuerpo del Correo' text box
body_label = tk.Label(root, text="Cuerpo del Correo", font=('Arial', 12, 'bold'))
body_label.grid(row=3, column=1, padx=10, pady=5, sticky='w')
body_text = tk.Text(root, height=10, width=60)
body_text.grid(row=4, column=1, padx=10, pady=5, sticky='ew')
# Add 'Enviar' button
sendP_button = tk.Button(root, text="Enviar", command=lambda: print("Enviar button pressed")) # Define button command
sendP_button.grid(row=5, column=1, pady=(20, 10), sticky="e", padx=(10, 5))
# Configure row and column weights to make the layout responsive
root.grid_columnconfigure(1, weight=1)
root.grid_rowconfigure(2, weight=1)
root.grid_rowconfigure(4, weight=1)
root.grid_rowconfigure(5, weight=1)
# Display the available variables as buttons
display_csv_variables()
如果您想查看标签小部件在哪里。
然后添加
tk.Label(root, bg='black',...)