Python Forum
Display value in the another entry field instead of message box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display value in the another entry field instead of message box
#1
Hello,

I do have a code where after pasting value into entry field number 1 and after clicking button Generate, functions re-organizes previosuly pasted value into another one. It is shown in the messagebox. However, I would like to have this value copyable and as we know message box blocks it. I thought that maybe this value could be shown in another entry field (with f or example state readonly) - what do you think? Maybe other ideas?

I am wondering how such code should look like?

Please see the part of my code:
insertcode1 = tk.Label(root,  text = "Insert SECRET CODE")
insertcode1.pack(side=LEFT)

entry1 = tk.Entry(root)
# entry1.config(bg = "grey")
entry1.pack(side=LEFT)

generatedimmoSK = tk.Label(root, text = "Generated IMMO SK")
generatedimmoSK.pack(side=LEFT)

generated = lambda:tk.messagebox.showinfo("showinfo", generate(entry1.get()))

entry2 = tk.Entry(root, state = 'readonly')
entry2.pack(side=LEFT)

buttonGenerate = tk.Button(root, relief = "ridge", text = "Generate", width = 20, height = 5, command = generated).pack() 
# # buttonGenerate.config(bg = "yellow")
I would like to show the value in entry2 insdtead of messagebox.
Reply
#2
Please edit your post and use a code block around the script.

When you say "copyable", what exactly do you mean?

If you mean that you want to be able to select the contents and use the C&P function (as you can with say a word processor) then the Text widget will allow you to do that.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#3
(Jun-24-2022, 09:40 PM)rob101 Wrote: Please edit your post and use a code block around the script.

When you say "copyable", what exactly do you mean?

If you mean that you want to be able to select the contents and use the C&P function (as you can with say a word processor) then the Text widget will allow you to do that.

Done. Hope it's ok now. By 'copyable' I mean exactly what you said, that I will be able to copy the value. Could you please advise how to use this text widget in my case?
Reply
#4
(Jun-24-2022, 09:46 PM)adisc Wrote: Done. Hope it's ok now. By 'copyable' I mean exactly what you said, that I will be able to copy the value. Could you please advise how to use this text widget in my case?

Sound: it makes for easier reading.

The best thing I can do is to point you to one of my 'go to' websites so that you can attempt this for yourself. Having done that, post back your amended code and we'll take it from there.

https://www.pythontutorial.net/tkinter/tkinter-text/
adisc likes this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#5
(Jun-24-2022, 09:54 PM)rob101 Wrote:
(Jun-24-2022, 09:46 PM)adisc Wrote: Done. Hope it's ok now. By 'copyable' I mean exactly what you said, that I will be able to copy the value. Could you please advise how to use this text widget in my case?

Sound: it makes for easier reading.

The best thing I can do is to point you to one of my 'go to' websites so that you can attempt this for yourself. Having done that, post back your amended code and we'll take it from there.

https://www.pythontutorial.net/tkinter/tkinter-text/

thanks rob101. I have added two text widgets and right now after clicking my Generate button it takes the value from input, but right now I do not know how to paste the new value into the ooutput text widget, please see the code:
input = Label(text = "Insert SECRET CODE HERE")
inputtxt = Text(root, height = 10, width = 25, bg = "light yellow")
input.pack()
inputtxt.pack()

output = Label (text = "Generated IMMO SK")
outputtxt = Text(root, height = 5, width = 25, bg = "light cyan", state = 'disabled')
output.pack()
outputtxt.pack()

# entry1 = tk.Entry(root)
# # entry1.config(bg = "grey")
# entry1.pack(side=LEFT)

# generatedimmoSK = tk.Label(root, text = "Generated IMMO SK")
# generatedimmoSK.pack(side=LEFT)

generated = lambda:("showinfo", generate(inputtxt.get("1.0",'end-1c')))

# entry2 = tk.Entry(root, state = 'readonly')
# entry2.pack(side=LEFT)

buttonGenerate = tk.Button(root, relief = "ridge", text = "Generate", width = 20, height = 5, command = generated).pack() 
# # buttonGenerate.config(bg = "yellow")
any suggestions?
Reply
#6
Nice one.

The next thing to do (maybe you'll need the define a function for this) is to set the state of your output text widget to 'normal', then use the insert() method to insert 'generated' into the output text widget, then set the state back to 'disabled'.

Understand that I'm typing this on-the-fly, having not tested any code: I'm simply going from my memory of having created an app, that uses these widgets and methods.

I trust that you found that link of use. I've learned 90% of my Tkinter skills from that site.

edit to add a code block.

This is my function that does just that.

def hashType():
    ht = hashSelect.get()
    if file:
        resultText['state']='normal'
        resultText.delete('1.0', tk.END)
        hd = hash_file(file, ht)
        resultText.insert('1.0', hd)
        resultText['state']='disabled'
    else:
        resultText['state']='normal'
        resultText.delete('1.0', tk.END)
        resultText['state']='disabled'
edit No2

If you get stuck, post your code in full and I'll have a look at it for you: I may have misunderstood what you're trying to do -- please excuse me if that's the case.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#7
One observation I do have, with regard to your code so far:

input = Label(text = "Insert SECRET CODE HERE")
'input' is a keyword in Python. You've used it here as a Tkinter Label Object. Best not to do this, as it can lead to a misunderstanding. Instead, use something such as 'inputLabel' or 'input_Label' which is descriptive and as such, when you (or anyone else) is reading the code, it's very obvious that this is a 'Label' object (Widget) that is being used as a part of the user input section.

It's a small point in short code blocks, but as you progress and develop code that is maybe 100s of lines in length, it's best to develop a good coding style at the same time.

In fact, I'm going to edit my code (this end) to use 'hash_Select' and 'result_Text' etc, as that's more readable'
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,918 May-06-2023, 08:14 AM
Last Post: pramod08728
  Auto increament in Entry field. in tkinter GUI cybertooth 7 4,095 Sep-17-2021, 07:56 AM
Last Post: cybertooth
  Display table field on multiple lines, 'wordwrap' 3python 0 1,769 Aug-06-2021, 08:17 PM
Last Post: 3python
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,226 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Bug ? when dataclass field name == field type Cyril 0 1,548 Oct-22-2020, 03:26 AM
Last Post: Cyril

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020