Using Entry box with Tkinter in Grid manager?

2019-07-21 06:06发布

I'm trying to make a basic GUI using Tkinter and have an entry box next to my label using a Grid manager, but the window is not showing when I run my program if I use .grid() with my Entry object.

It does work when I use .pack(), which is strange because I heard not to use .pack() when I have other things using .grid() in the same widget. But I do want to use .grid() because I want to be able to organize it how I want to.

Code is below, I'm having trouble with Entry object showName. The commented out .pack() statement is the one that does work, the .grid() statement is the one that does not work.

Does anybody know what's wrong with this?

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)

1条回答
等我变得足够好
2楼-- · 2019-07-21 06:43

The entry has the wrong parent:

self.showName = Entry(master)

should be

self.showName = Entry(frame)
查看更多
登录 后发表回答