在同一列中设置单选按钮和条目的位置,但结果不对齐
Set the position of radio button and entry in same column but the result was not allign
我使用网格几何管理器将条目的位置设置为与文本"Specific Location"在同一行,但最终结果却像this。我只是想知道为什么位置不按设置,解决方法谢谢^^
这是我如何设置条目和单选按钮的编码
tm_label = Label(self.radioframe, text = "Tracing Method")
tm_label.grid(row=0, columnspan=2 ,sticky = W)
self.radioframe.LT = Radiobutton(
self.radioframe, text="Live Tracing",
variable=self.traceMethodSelect, value="LT",
anchor=W).grid(row=1, column = 0, sticky = W)
self.radioframe.SL= Radiobutton(
self.radioframe, text="Specific Location",
variable=self.traceMethodSelect, value="SL",
anchor=W).grid(row=2, column = 0, sticky = W)
location_ent =Entry(root)
location_ent.grid(row =2, column = 1, sticky = W)
我的全部代码在这里:
from tkinter import *
class TracingInterface(Frame):
def __init__(self, root):
root.minsize(width=700, height=500)
root.maxsize(width=700, height=500)
Frame.__init__(self, root)
Grid.config(self)
self.TracingMethod()
def TracingMethod(self):
self.traceMethodSelect = StringVar()
self.traceMethodSelect.set("LT")
self.radioframe = Frame(self)
self.radioframe.grid()
tm_label = Label(self.radioframe, text = "Tracing Method")
tm_label.grid(row=0, columnspan=2 ,sticky = W)
self.radioframe.LT = Radiobutton(
self.radioframe, text="Live Tracing",
variable=self.traceMethodSelect, value="LT",
anchor=W).grid(row=1, column = 0, sticky = W)
self.radioframe.SL= Radiobutton(
self.radioframe, text="Specific Location",
variable=self.traceMethodSelect, value="SL",
anchor=W).grid(row=2, column = 0, sticky = W)
location_ent =Entry(root)
location_ent.grid(row =2, column = 1, sticky = W)
root = Tk()
root.title("Windows User Activity History Tracing and Analysing System")
tif= TracingInterface(root)
root.mainloop()
您需要在包含单选按钮的同一个容器小部件 self.radioframe
中绘制 location_ent。这意味着您需要更改:
location_ent =Entry(root)
至:
location_ent =Entry(self.radioframe)
.
演示
如果你执行上面的修改,你会得到你期望的:
我使用网格几何管理器将条目的位置设置为与文本"Specific Location"在同一行,但最终结果却像this。我只是想知道为什么位置不按设置,解决方法谢谢^^
这是我如何设置条目和单选按钮的编码
tm_label = Label(self.radioframe, text = "Tracing Method")
tm_label.grid(row=0, columnspan=2 ,sticky = W)
self.radioframe.LT = Radiobutton(
self.radioframe, text="Live Tracing",
variable=self.traceMethodSelect, value="LT",
anchor=W).grid(row=1, column = 0, sticky = W)
self.radioframe.SL= Radiobutton(
self.radioframe, text="Specific Location",
variable=self.traceMethodSelect, value="SL",
anchor=W).grid(row=2, column = 0, sticky = W)
location_ent =Entry(root)
location_ent.grid(row =2, column = 1, sticky = W)
我的全部代码在这里:
from tkinter import *
class TracingInterface(Frame):
def __init__(self, root):
root.minsize(width=700, height=500)
root.maxsize(width=700, height=500)
Frame.__init__(self, root)
Grid.config(self)
self.TracingMethod()
def TracingMethod(self):
self.traceMethodSelect = StringVar()
self.traceMethodSelect.set("LT")
self.radioframe = Frame(self)
self.radioframe.grid()
tm_label = Label(self.radioframe, text = "Tracing Method")
tm_label.grid(row=0, columnspan=2 ,sticky = W)
self.radioframe.LT = Radiobutton(
self.radioframe, text="Live Tracing",
variable=self.traceMethodSelect, value="LT",
anchor=W).grid(row=1, column = 0, sticky = W)
self.radioframe.SL= Radiobutton(
self.radioframe, text="Specific Location",
variable=self.traceMethodSelect, value="SL",
anchor=W).grid(row=2, column = 0, sticky = W)
location_ent =Entry(root)
location_ent.grid(row =2, column = 1, sticky = W)
root = Tk()
root.title("Windows User Activity History Tracing and Analysing System")
tif= TracingInterface(root)
root.mainloop()
您需要在包含单选按钮的同一个容器小部件 self.radioframe
中绘制 location_ent。这意味着您需要更改:
location_ent =Entry(root)
至:
location_ent =Entry(self.radioframe)
.
演示
如果你执行上面的修改,你会得到你期望的: