这是我第一次编写 GUI 程序。我希望将标签放在输入文本框的左侧,并在 GUI 的中心对齐,但我不知道该怎么做,任何人都可以提供帮助,将不胜感激
(注意:这是一个无功能的 GUI 示例。我没有添加任何有关文本框或按钮如何工作的代码。稍后将添加它们)
import tkinter as tk
root = tk.Tk()
root.geometry("400x400")
root.configure(bg='White')
root.title("Search your class information")
# Create a label with background and foreground colors
label = tk.Label(root, text="Search your for your class using one or more of the search criteria", bg="white", fg="black")
label.pack()
label = tk.Label(root, text="Enter Text:")
label.pack()
entry = tk.Entry(root, selectbackground="lightblue", selectforeground="black")
entry.pack()
# Create a button with active background and foreground colors
button = tk.Button(root, text="Search", activebackground="blue", activeforeground="white")
button.pack()
root.mainloop()
只需将标签和条目放入框架中即可:
import tkinter as tk
root = tk.Tk()
root.geometry("400x400")
root.configure(bg='White')
root.title("Search your class information")
# Create a label with background and foreground colors
label = tk.Label(root, text="Search your for your class using one or more of the search criteria", bg="white", fg="black")
label.pack()
# frame for the label and entry box
frame = tk.Frame(root)
frame.pack()
# created as child of the above frame
label = tk.Label(frame, text="Enter Text:")
label.pack(side='left')
# created as child of above frame
entry = tk.Entry(frame, selectbackground="lightblue", selectforeground="black")
entry.pack(side='left')
# Create a button with active background and foreground colors
button = tk.Button(root, text="Search", activebackground="blue", activeforeground="white")
button.pack()
root.mainloop()
输出