英文:
Adding a Logo image on top left of tkinter window along with the title in same line
问题
以下是代码部分的翻译:
def __init__(self, root):
self.root = root
self.root.title("Data Wizard: Automated Data Preprocessing")
self.root.geometry("800x600")
self.root.configure(bg='#005792')
# 顶部布局,包括标题
self.title_label = tk.Label(self.root, text="Data Wizard: Automated Data Preprocessing", font=("Times New Roman", 22))
self.title_label.pack(pady=20)
self.title_label.configure(bg='#005792', fg='#7dd8c5')
# 中部布局,包括表格框架
self.table_frame = tk.Frame(self.root, bd=2, relief=tk.GROOVE)
self.table_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=10)
# 创建一个用于显示表格的treeview部件
self.tree = ttk.Treeview(self.table_frame, selectmode='browse')
self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 为treeview部件添加滚动条
scrollbar = ttk.Scrollbar(self.table_frame, orient="vertical", command=self.tree.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.tree.configure(yscrollcommand=scrollbar.set)
# 底部布局,包括上传CSV文件标签和按钮
self.bottom_frame = tk.Frame(self.root, bd=2, relief=tk.GROOVE)
self.bottom_frame.pack(fill=tk.X, padx=20, pady=10)
self.bottom_frame.configure(bg='#C3C3C3')
self.upload_label = tk.Label(self.bottom_frame, text="Upload CSV File", font=("Arial", 12))
self.upload_label.pack(side=tk.LEFT, padx=10, pady=10)
self.upload_label.configure(bg='#C3C3C3', fg='#0b1956')
self.upload_button = tk.Button(self.bottom_frame, text="Browse", command=self.upload_csv)
self.upload_button.pack(side=tk.RIGHT, padx=10, pady=10)
self.new_frame = tk.Frame(self.root, bd=0, relief=tk.GROOVE)
self.new_frame.pack(fill=tk.X, padx=20, pady=10)
self.new_frame.configure(bg='#005792')
# 添加打开新窗口的按钮
self.new_window_button = tk.Button(self.new_frame, text="Next", command=self.open_new_window)
self.new_window_button.pack(side=tk.RIGHT, padx=10, pady=10)
希望这个翻译对你有所帮助。如果你有其他问题,请随时提出。
英文:
I have this logo below and I have to add it in the tkinter window, the logo shall be aligned to top left of window but in same line as the title label.
def __init__(self, root):
self.root = root
self.root.title("Data Wizard: Automated Data Preprocessing")
self.root.geometry("800x600")
self.root.configure(bg='#005792')
# Top layout with title
self.title_label = tk.Label(self.root, text="Data Wizard: Automated Data Preprocessing", font=("Times New Roman", 22))
self.title_label.pack(pady=20)
self.title_label.configure(bg='#005792', fg='#7dd8c5')
# Middle layout with table frame
self.table_frame = tk.Frame(self.root, bd=2, relief=tk.GROOVE)
self.table_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=10)
# Create a treeview widget to display table
self.tree = ttk.Treeview(self.table_frame, selectmode='browse')
self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Add scrollbar to the treeview widget
scrollbar = ttk.Scrollbar(self.table_frame, orient="vertical", command=self.tree.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.tree.configure(yscrollcommand=scrollbar.set)
# Bottom layout with Upload CSV file label and button
self.bottom_frame = tk.Frame(self.root, bd=2, relief=tk.GROOVE)
self.bottom_frame.pack(fill=tk.X, padx=20, pady=10)
self.bottom_frame.configure(bg='#C3C3C3')
self.upload_label = tk.Label(self.bottom_frame, text="Upload CSV File", font=("Arial", 12))
self.upload_label.pack(side=tk.LEFT, padx=10, pady=10)
self.upload_label.configure(bg='#C3C3C3', fg='#0b1956')
self.upload_button = tk.Button(self.bottom_frame, text="Browse", command=self.upload_csv)
self.upload_button.pack(side=tk.RIGHT, padx=10, pady=10)
self.new_frame = tk.Frame(self.root, bd=0, relief=tk.GROOVE)
self.new_frame.pack(fill=tk.X, padx=20, pady=10)
self.new_frame.configure(bg='#005792')
# Add button to open a new window
self.new_window_button = tk.Button(self.new_frame, text="Next", command=self.open_new_window)
self.new_window_button.pack(side=tk.RIGHT, padx=10, pady=10)
The window is
I also tried this following code to do so, and also the PIL methods to do this
# Create a PhotoImage object from the image file
my_img = tk.PhotoImage(file="C:/Users/pdhin/Minor 2/Logo_New.png")
# Create the title label with the image to the left of the text
self.title_label = tk.Label(self.root, text="Data Wizard: Automated Data Preprocessing", font=("Times New Roman", 22), image=my_img, compound="left")
self.title_label.pack(pady=20)
self.title_label.configure(bg='#005792', fg='#7dd8c5', anchor="e")
But everytime an error like this pops up
答案1
得分: 1
the logo shall be aligned to top left of window but in same line as the title label.
将标志对齐到窗口的左上角,但与标题标签在同一行上。
Add self.
to self.my_img = ...
在 self.my_img = ...
中添加 self.
。
英文:
> the logo shall be aligned to top left of window but in same line as
> the title label.
Add self.
to self.my_img = ...
Code:
class App:
def __init__(self, root):
...
self.my_img = tk.PhotoImage(file="p2.png")
# Top layout with title
self.title_label = tk.Label(self.root, text="Data Wizard: Automated Data Preprocessing",
font=("Times New Roman", 22), image=self.my_img, compound="left")
Screenshot:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论