0

I set up a large entry box using

    self.answer_entry = ttk.Entry(self, text='Answer')
    self.answer_entry.grid(column=0, row=6, columnspan=3, sticky='nesw')
    self.answer_entry.grid(ipady=50)

I haven't been able to find a way to align the text to the top of it so I wanted to play with Text instead of Entry. When I try and change it to Text, I always get an error that says "Tkinter.ttk has no attribute 'Text'"

Entry works with this code:

def init_gui(self):
    """Builds GUI."""
    self.root.title('Verify')
    self.root.option_add('*tearOff', 'FALSE')

    self.grid(column=0, row=0, sticky='nsew') # this starts the entire form

    self.menubar = tkinter.Menu(self.root)

    self.menu_file = tkinter.Menu(self.menubar)
    self.menu_file.add_command(label='About', command=self.on_help)
    self.menu_file.add_command(label='Exit', command=self.on_quit)

    self.menu_edit = tkinter.Menu(self.menubar)

    self.menubar.add_cascade(menu=self.menu_file, label='File')


    self.root.config(menu=self.menubar)

    self.workstation1_entry = ttk.Entry(self, width=30)
    self.workstation1_entry.grid(sticky='e', column=0, row=3)

    self.localid2_entry = ttk.Entry(self, width=30)
    self.localid2_entry.grid(sticky='e', column=1, row=3) 

    self.localid3_entry = ttk.Entry(self, width=30)
    self.localid3_entry.grid(sticky='e', column=2, row=3)

    self.calc_button = ttk.Button(self, text='Search', command=self.calculate) # button
    self.calc_button.grid(column=0, row=5, columnspan=3)

    self.answer_entry = ttk.Entry(self, text='Answer')
    self.answer_entry.grid(column=0, row=6, columnspan=3, sticky='nesw')
    self.answer_entry.grid(ipady=50)

How come I can't just change

 self.answer_entry = ttk.Entry(self, text='Answer')

to something like

 self.answer_entry = ttk.Text(self, text='Answer')

2 Answers 2

2

Why do I get tkinter has no attribute 'Text' error in Python Tkinter?

I hate to say it, but the answer is as simple as "you get that error because the ttk module does not have a Text widget". Why? Ask the people that created the module.

If you want a text widget, use the one in the tkinter module.

Sign up to request clarification or add additional context in comments.

3 Comments

Maybe it is due to the fact that there is not much to style, and most users won't even notice. In macOS, I change the highlightcolor to "LightSteelBlue2" so it really blends with the rest of the interface and looks almost like a native widget.
ahhhhh lol That explains a lot. I've thinking the modules were the same thing and wondering why all the examples I find don't work. I'm stupid. haha
@Prox: they are two different modules with overlapping features.
0

You can also use Label, either in tkinter or ttk:

self.answer_entry = ttk.Label(self, text='Answer')

or

self.answer_entry = tkinter.Label(self, text='Answer')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.