我正在尝试使用Tkinter创建一个基本的GUI,并使用网格管理器在我的标签旁边有一个输入框,但是如果我使用.grid()和我的Entry对象运行我的程序时窗口没有显示。
当我使用.pack()时它确实有效,这很奇怪,因为当我在同一个小部件中使用.grid()时,我听说不要使用.pack()。但我确实想使用.grid(),因为我希望能够按照我想要的方式组织它。
代码如下,我在使用Entry对象showName时遇到问题。注释掉的.pack()语句是可行的,.grid()语句是不起作用的语句。
有人知道这有什么问题吗?
from Tkinter import *
class RenamerGUI():
def __init__(self, master):
frame = Frame(master)
frame.pack() #Make frame visible
self.exit = Button(frame, text = "Exit", fg = "red", command = frame.quit)
self.csv2tsv = Button(frame, text = "csv2tsv", fg = "green", bg = "black", command=self.csv2tsv)
self.epguidestsvFormatter = Button(frame, text = "epguidestsvFormatter", fg = "green", bg = "black", command = self.epguidestsvFormatter)
self.epNamesList = Button(frame, text = "epNamesList", fg = "green", bg = "black", command = self.epNamesList)
self.SeasonSplitter = Button(frame, text = "SeasonSplitter", fg = "green", bg = "black", command = self.SeasonSplitter)
self.Renamer = Button(frame, text = "Renamer", fg = "green", bg = "black", command = self.Renamer)
self.showLabel = Label(frame, text = "Show: ")
self.showName = Entry(master)
self.get = Button(frame, text = "Get", command = self.textgetter)
self.exit.grid(row=3, column=4)
self.csv2tsv.grid(row=1, column = 0)
self.epguidestsvFormatter.grid(row=1, column=1)
self.epNamesList.grid(row=1, column=2)
self.SeasonSplitter.grid(row=1, column=3)
self.Renamer.grid(row=1, column=4)
self.showLabel.grid(row=2)
self.showName.grid(row=2, column=1)
#self.showName.pack(side=BOTTOM)
答案 0 :(得分:2)
该条目包含错误的父级:
self.showName = Entry(master)
应该是
self.showName = Entry(frame)