我正在用tkinter用Python编写一个小GUI程序。我现在在“文本”和“标签”小部件周围存在垂直对齐和间距问题。有两种情况。
文本小部件及其边框/高亮之间的垂直间距,如前三个文本小部件所见。即使使用pady,它也会以不均匀的方式变大
从标签到文本小部件的垂直对齐也处于关闭状态。这里我根本不知道如何影响它。
我正在(manjaro)linux上运行它。
Screenshot of the minimal example
import tkinter as tk
class GuiTest():
def __init__(self, root):
self.root = root
root.wm_title("GUI Test")
root.geometry("800x600")
root.attributes('-type', 'dialog')
baseinfo = tk.Frame(root, padx=10, pady=10)
baseinfo.grid(row = 4, column=4, sticky='EW')
self.loc = tk.Text(baseinfo, width=10, height=1, bd=0, highlightthickness=1, font=("Courier", "14"))
self.loc.grid(row=1, column=1)
self.year = tk.Text(baseinfo, width=15, height=1, bd=1, highlightthickness=1, font=("Courier", "14"))
self.year.grid(row=1, column=2)
self.typ = tk.Text(baseinfo, width=10, height=1, bd=0, highlightthickness=1, font=("Courier", "14"), pady='10')
self.typ.grid(row=2, column=1)
tk.Label(baseinfo, text="Label").grid(row=3, column=3)
self.col = tk.Text(baseinfo, width=15, height=1, bd=0, highlightthickness=0, font=("Courier", "11"))
self.col.grid(row=3, column=4)
self.loc.insert('end', "Test")
self.year.insert('end', "another Test")
self.col.insert('end', "Color")
self.typ.insert('end', "More Text")
self.col.configure(background='red')
if __name__ == '__main__':
root = tk.Tk()
app = GuiTest(root)
root.mainloop()
如果代码中有大的NoNo,请告诉我,我仍然是tkinter的初学者。
谢谢
如@stovfl所指出这是我的系统而不是代码的问题。在reply.it]上运行正常