Better Method of Creating Multi Line Text Entry? - python

I need to create a message box for a user in a GUI with tkinter. For 3/4 of my entries, Entry(master, options. . .,) works. But for a message box, I need a multi line entry.
How would I do this? I tried ScrolledText(root).pack(), but it doesn't have the same commands/variables as Entry.

It is not explicitly mentioned in the documentation, but even if the tkinter.Entry widget's content can be scrolled, it can only be scrolled horizontally meaning that you can not use the yscrollcommandoption unlike with Canvas, Text and Listbox widgets.
This means technically your goal is not feasible, I mean you can not write multiple lines inside an Entry widget so that you scroll them vertically but only horizontally:
(if you need the code of this screenshot, please let me know).

Billal is right, however i would recomend simply using a Textbox.
go to: http://www.tutorialspoint.com/python/tk_text.htm
for more information

Related

How can I create a read-only text widget with TkInter and still be able to modify the widget's content programmatically?

I want to use Tk's text widget to display part of the state of my program. (A label widget will not do, because the tag feature of the text widget will save a lot of work. A canvas widget will not do, because I don't want to have to lay out a lot of text manually.)
I do not want the user to be able to directly modify the contents of the text widget. They can change the state of the program by interacting with it in other ways, but the text widget is for display only.
If I set the state of the text widget to disabled, then not only is the user unable to interact with it, but I also cannot modify its contents programmatically (specifically, I cannot insert text).
The obvious workaround is decorate any code that updates the contents of the text widget with code the enables and disables the widget. But this is kludgy: I should be able to modify the contents without offering the user an opportunity to interfere, however brief that opportunity may be.
Is there a way to do this?
The "kludgy workaround" isn't kludgy at all -- that's exactly how you do it, and how it was designed to work.
However, there is another solution. You can remove all of the built-in key and mouse bindings from the widget, and then re-implement only the ones you care about (for example, you might want the user to highlight and copy a block of text). This is simple and effective, but if you want to restore some of the bindings it starts to become very tedious to re-implement the bindings you care about (cut, copy, paste, page up, page down, moving the cursor, etc).
To remove all of the default bindings you can remove the class bind tag like this:
t.bindtags((t, root, "all"))
For more information about bind tags, see these answers:
https://stackoverflow.com/a/11542200/7432
https://stackoverflow.com/a/3513906/7432
https://stackoverflow.com/a/11459001/7432
you could constantly delete then insert the text like so:
import tkinter
root = tkinter.Tk()
text = tkinter.Text(root, width=40)
text.grid(row=0, column=0, stciky=tkinter.W)
while True:
text.delete(0.0, tkinter.END)
text.insert(tkinter.END, your_text)
where your_text is the text you want to insert

Modifying a Part of Text on tk.Button

I wonder if it is possible to change the weight of one word on a tkinter button? So the result would look something like this:
[ yes, I agree ]
I've tried using tags but neither tk.Button nor tk.Button['text'] seem to allow it.
Thanks!
No, it's not possible. If you want a button with rich text you'll have to create your own. Or, create an image that has the look you want, and use the image with a standard button.
You can create your own using a text widget that is one character tall and a few characters wide. Then, you can place bindings on the button to handle clicks, and to change the relief to simulate a button. Unfortunately, it won't have the look of the platform-specific buttons.

Add a scrollbar to a Tkinter Label?

I was wondering if I can add a scrollbar to a Label or not?
I followed this tutorial to create a simple terminal GUI with a Button and a TextField. The problem is that, unlike what's in the tutorial , I need my Label to contain more than just a single line
Any alternatives? I want something exactly like this tutorial, but with more lines and a scrollbar for the Label (I already limited its size, but no scrollbar).
You cannot add a scrollbar to a Label.
If you want multiple lines of text that can be scrolled, use a Text widget.

Python tkinter: a scrollable list with text and images?

I'm using python 2.7 and I'd like to have an GUI with a scrollable list where each item in the list has both an image and some text. I'd like these items to be selectable like in a ListBox. I've tried a couple things and it seems ListBox only accepts text?
What widget/combination of widgets should I use?
Try placing a whole bunch of buttons in a frame and assigning a scroll bar a to that frame and make it so when the user presses a button is changes colour or picture or something and then any button with that same colour of picture before will go back to normal. Also, and a tkinter variable with which button is active so you can reference it later.
I'm fairly sure you can use both texts and images in a button simultaneously, but if not you can just put a button and an image side by side in the same row on the frame
I recommend you make this entire scrolling object a class and keep references of everything inside within that class.
If you need any help doing this, just give me a shout.

Textvariable in tkinter CheckButton

I'm writing a GUI program where I want to create several check buttons with text from a list. The problem is that I have many lists, and I therefore want the user to be able to go to the "next page" and see a different set of check buttons based on a different list. However, to do this I need some kind of textvariable in my check buttons so the text is updated every time a user goes to the next page. Though, as far as I know, there is no such option.
Is this possible to do, or do I need to create a separate check button and a separate label with the textvariable in it?
Help would be much appreciated. Thanks in advance!
Only possible approach I can think of is doing config on a checkbutton. Assuming you are using standard tk checkbuton, you can call:
checkbutton.config(text=newtext)
where newtext is the new text, obviously.
Add the call to the callback bound to the next and previous page buttons. If you really need to use a variable, add a property to a class based on checkbutton and modify its setter to call the config function on asignment.

Categories

Resources