Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python Tkinter中小部件的对齐_Python 3.x_Tkinter_Widget - Fatal编程技术网

Python 3.x Python Tkinter中小部件的对齐

Python 3.x Python Tkinter中小部件的对齐,python-3.x,tkinter,widget,Python 3.x,Tkinter,Widget,我要为这个愚蠢的问题发疯了。正如您在运行此简单代码时所看到的,combobox小部件与其他条目小部件不一致。我错在哪里 from tkinter import * from tkinter import ttk root = Tk() frame = Frame(root) frame.grid() x = Label(frame, text="alpha", width = 8, anchor = W) x.grid(row=1, columnspan=1) x = Entry(fram

我要为这个愚蠢的问题发疯了。正如您在运行此简单代码时所看到的,combobox小部件与其他条目小部件不一致。我错在哪里

from tkinter import *
from tkinter import ttk

root = Tk()

frame = Frame(root)
frame.grid()

x = Label(frame, text="alpha", width = 8, anchor = W)
x.grid(row=1, columnspan=1)
x = Entry(frame,  width = 24)
x.grid(row=1, column=2, columnspan=2,  sticky=W)

x = Label(frame, text="beta", width = 8, anchor = W)
x.grid(row=2, columnspan=1)
x = Entry(frame,  width = 24)
x.grid(row=2, column=2, columnspan=2,  sticky=W)

x = Label(frame, text="gamma", width = 8, anchor = W)
x.grid(row=3, columnspan=1)
x = Entry(frame, width = 7, justify = 'center')
x.grid(row=3, column=2, columnspan=1, sticky=W)
#x = ttk.Combobox(frame, width = 4, justify = "center")
#x.grid(row=3, column=3, columnspan=1, sticky=W)

x = Label(frame, text="delta", width = 8, anchor = W)
x.grid(row=4, columnspan=1)
x = ttk.Combobox(frame, width=20)
x.grid(row=4, column=2, columnspan=2,  sticky=W)

x = Label(frame, text="epsilon", width = 8, anchor = W)
x.grid(row=5, columnspan=1)
x = Entry(frame,  width = 24)
x.grid(row=5, column=2, columnspan=2,  sticky=W)

mainloop()

不知道它为什么这么做。它在Windows和Linux上的显示方式不同。我从来没有遇到过这个问题。您可以在combobox grid语句中,在检测到Linux安装时添加padx=1,如果是Windows,则在需要多平台兼容性时不添加padx。我知道这是一个解决方法,但两个系统的基本GUI行为是不同的

import platform
from tkinter import *
from tkinter import ttk

os_info = platform.platform()
....

if os_info.startswith('Linux'):
    x.grid(row=3, column=2, columnspan=1, sticky=W, padx=1)
elif os_info.startswith('Windows'):
    x.grid(row=3, column=2, columnspan=1, sticky=W)
...

哪个组合框?你的代码有两个。你在问什么样的对齐方式?垂直对齐?左边缘对齐?右边缘?二者都好吗?对不起,我不清楚。名为delta的组合框与条目小部件没有左对齐。我觉得它是对齐的。路线有多远?就一两个像素?你在什么平台上运行?Mint18.1-Python3.5.2-只有几个像素,但看起来很难看。看屏幕截图。