Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Entry box with Tkinter in Grid manager?

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)
like image 957
Donuts Avatar asked Dec 05 '25 12:12

Donuts


1 Answers

The entry has the wrong parent:

self.showName = Entry(master)

should be

self.showName = Entry(frame)
like image 130
Vaughn Cato Avatar answered Dec 08 '25 02:12

Vaughn Cato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!