python - Python tkinter 文本到边界问题
问题描述
我正在用 tkinter 在 Python 中编写一个小 GUI 程序。我现在遇到了文本和标签小部件周围的垂直对齐和间距问题。有两种情况。
案例一
文本小部件与其边框/突出显示之间的垂直间距,如前 3 个文本小部件所见。即使我使用pady,它也会以不均匀的方式变大
案例二
从标签到文本小部件的垂直对齐也关闭了。在这里我完全不知道如何影响它。
我在 (manjaro) linux 上运行它。
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()
如果代码中有任何大的 NoNos,请告诉我们,我仍然是 tkinter 的初学者。
谢谢
解决方案
正如@stovfl 指出的那样,这是我的系统问题,而不是代码问题。它在reply.it上运行良好
推荐阅读
- qt - 如何在 yocto 食谱中嵌入文件
- python - 带有滚动窗口的 Pandas 函数
- php - 如何在 laravel 中间件中收听 GET 参数
- python - 并排附加 2 个 Pandas 数据帧
- modelica - Modelica 如何检查结构奇点?
- .net - 依赖注入的服务返回 null
- arrays - 使用 jq 将两个 JSON 数组合并到一个文件中
- angular - ViewChild 从子组件返回到父组件时返回 undefined
- wordpress - 如何从永久 URL 中删除“百分比”(%)?
- batch-file - 调用doxygen时在命令行中配置一些变量