Как это выглядит прямо сейчас < /p>
Может ли кто -нибудь помочь мне выровнять коробки горизонтально и вертикально? На изображении поле записи сообщения и остальные 4 коробки выровнены. Поле входа в сообщение должно быть той же длиной, что и Frame1 и Frame2. И коробки внутри рамков имеют разные длины. Они должны быть такой же длины и выровнять с красными линиями. Например, это должно выглядеть как это изображение: как я хочу, чтобы оно выглядело < /p>
Это точный код, который у меня есть: < /p>
import tkinter as tk
from tkinter import ttk, filedialog
from PIL import Image, ImageTk
import sys
import os
root = tk.Tk(className="Chat APP")
root.title("Chat APP")
# Maximize the window
root.attributes('-zoomed', True)
# Get the screen width and height
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
new_note_icon = Image.open("new_note.jpg")
new_note_icon = new_note_icon.resize((25, 25))
new_note_icon = ImageTk.PhotoImage(new_note_icon)
# Proportional calculations
def proportion_width(p):
return int(screen_width * p)
def proportion_height(p):
return int(screen_height * p)
chat_frame = tk.Frame(root, bg='white')
chat_frame.pack(expand=True, fill=tk.BOTH)
chat_frame.grid_rowconfigure(0, weight=0)
chat_frame.grid_rowconfigure(1, weight=1)
chat_frame.grid_columnconfigure(0, weight=1)
chat_log = tk.Text(chat_frame, state='disabled', wrap='word', width=70, height=15,
font=('Helvetica', 14), bg="white", fg="black", highlightthickness=0, borderwidth=0)
chat_log.grid(row=1, column=0, sticky='NESW', padx=proportion_width(0.275), pady=proportion_height(0.01))
# Create a scrollbar for the chat log
scrollbar = tk.Scrollbar(chat_frame, command=chat_log.yview)
scrollbar.grid(row=1, column=1, sticky='NS')
chat_log['yscrollcommand'] = scrollbar.set
frame1 = tk.Frame(root, bg="white")
frame1.pack(side=tk.TOP, pady=(proportion_height(0.1), 1))
frame2 = tk.Frame(root, bg="white")
frame2.pack(side=tk.TOP, pady=(proportion_height(0.005), proportion_height(0.02)))
print("Width is",chat_frame.winfo_width())
chat_with_pdf_button = ttk.Button(frame1, width=proportion_width(0.02), text="Chat with PDF", style="def2.TButton",)
chat_with_pdf_button.pack(side=tk.LEFT, padx=(proportion_width(0.0843),0), ipady=proportion_height(0.01))
# Create a button to trigger the summarization process
summarize_button = ttk.Button(frame1, width=proportion_width(0.02), text="Chat with a YouTube video", style="def2.TButton")
summarize_button.pack(side=tk.LEFT, padx=(proportion_height(0.01), 0), ipady=proportion_height(0.01))
letter_button = ttk.Button(frame2, width=proportion_width(0.02), text="Write a letter", style="def2.TButton")
letter_button.pack(side=tk.LEFT, padx=(proportion_width(0.0843),0), ipady=proportion_height(0.01))
blog_button = ttk.Button(frame2, width=proportion_width(0.02), text="Chat with a Blog Post", style="def2.TButton")
blog_button.pack(side=tk.LEFT, padx=(proportion_height(0.01), 0), ipady=proportion_height(0.01))
new_note_button = ttk.Button(chat_frame, style="Toggle.TButton", image=new_note_icon)
new_note_button.grid(row=0, column=0, sticky='W', padx=(proportion_width(0.272), 0), pady=(proportion_height(0.01), 0))
# Frame to contain message_entry and buttons
frame_for_widgets = tk.Frame(root, bg="white")
frame_for_widgets.pack(side=tk.BOTTOM)
empty_space = tk.Text(
frame_for_widgets, # Use frame2 as the parent widget
width=proportion_width(0.001), # Adjusting padx proportionally
bg="white",
borderwidth=0,
# Removing fixed width and height, so it expands with the frame
height=proportion_width(0.000001),
# Set a fixed height if needed
spacing1=proportion_height(0.02), # Adjust spacing1 proportionally
spacing3=proportion_height(0.02), # Adjust spacing3 proportionally
font=('Helvetica', 14)
)
message_entry = tk.Text(
frame_for_widgets, # Use frame2 as the parent widget
width=proportion_width(0.0495), # Adjusting padx proportionally
bg="white",
insertbackground='white',
fg="white",
borderwidth=0,
# Removing fixed width and height, so it expands with the frame
height=proportion_width(0.000001),
# Set a fixed height if needed
spacing1=proportion_height(0.02), # Adjust spacing1 proportionally
spacing3=proportion_height(0.02), # Adjust spacing3 proportionally
font=('Helvetica', 14)
)
# Pack message_entry into frame2
message_entry.pack(
side=tk.LEFT,
padx=(proportion_width(0.208),0),
#fill=tk.X, # Fill horizontally
pady=(0, proportion_height(0.02))
#padx=(0),
# Adjusting padx proportionally
# Adjusting pady proportionally
)
message_entry.mark_set("insert", "%d.%d" % (0,0))
send_icon = Image.open("send_icon.png")
send_icon = send_icon.resize((55, 55))
send_icon = ImageTk.PhotoImage(send_icon)
# Send button
send_button = ttk.Button(frame_for_widgets, image=send_icon, style="Send.TButton")
send_button.image = send_icon
send_button.pack(side=tk.LEFT, pady=(0, proportion_height(0.02)), padx=(1,0),)
message_entry.focus_set()
root.mainloop()
< /code>
Проблема в том, что эти выравнивания выглядят по -разному для разных размеров экрана. Он должен быть выровнен для всех размеров экрана; Независимо от размера экрана компьютера.
Подробнее здесь: https://stackoverflow.com/questions/794 ... on-tkinter
Нужно выравнивать коробки горизонтально и вертикально в Python Tkinter ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Нужно выравнивать коробки горизонтально и вертикально в Python Tkinter
Anonymous » » в форуме Python - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Нужно выравнивать коробки горизонтально и вертикально в Python Tkinter
Anonymous » » в форуме Python - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-