Python Forum

Full Version: Display value in the another entry field instead of message box
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
(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?
(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/
(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?
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.
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'