Closed fiddybux closed 6 years ago
Hi @fiddybux , I don't quite understand your problem.
You have a text box or a code box. You (the user) enters some value into that box. What do you want to do with the return value (the user entered value)? If you store it as a variable then you can use it within Python, or pass it through to a new box as desired. You don't have to print it to console, or lose it.
Could you provide a code segment, or additional description of the scenario, to help me understand it please?
Hi,
Thanks for the prompt reply.
Working in Python 3.4.2, I'm trying to count 0 and 1 characters in a short test file that looks like this, and present it in easygui:
0 00 1111
As requested, here is a code snippet. At the moment, I'm getting the error:
Exception when trying to convert <class 'tuple'> to text in self.textArea
The code:
import easygui
msg_a = ("Print file contents first (y/n)?") title_a = "Please Confirm" msg_b = ("Character count results...") title_b = "Result"
input_file = open('
x = file_content.count('0') y = file_content.count('1')
if easygui.ynbox(msg_a, title_a): pass easygui.codebox('', '', (file_content, ("\n"), x, ("\n"), y)) else: easygui.codebox(msg_b, title_b, (x, ("\n"), y))
If I run the same code but without the easygui elements, with added print lines for x and y, it works fine.
For example:
input_file = open('
x = file_content.count('0') y = file_content.count('1')
print("Print x:", x) print("Print y:", y)
Here, I get the expected result of 3 zero's and 4 one's, as per my test file, but naturally only within the python interpreter.
I can pass simple strings into easygui, as such ('hammer' and 'time'):
import easygui
msg_a = ("Print file contents first (y/n)?") title_a = "Please Confirm" msg_b = ("Just print hammer time...") title_b = "Result"
input_file = open('/home/russell/Dropbox/python/coding' '/01vshort.txt', 'r') file_content = input_file.read() input_file.close()
x = 'hammer' y = 'time'
if easygui.ynbox(msg_a, title_a): pass easygui.codebox('', '', (file_content, ("\n"), x, ("\n"), y)) else: easygui.codebox(msg_b, title_b, (x, ("\n"), y))
I've put about 6 hours into this today. Where am I going wrong?
Thanks.
On 25 September 2017 at 22:20, zadacka notifications@github.com wrote:
Hi @fiddybux https://github.com/fiddybux , I don't quite understand your problem.
You have a text box or a code box. You (the user) enters some value into that box. What do you want to do with the return value (the user entered value)? If you store it as a variable then you can use it within Python, or pass it through to a new box as desired. You don't have to print it to console, or lose it.
Could you provide a code segment, or additional description of the scenario, to help me understand it please?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/robertlugg/easygui/issues/130#issuecomment-332016781, or mute the thread https://github.com/notifications/unsubscribe-auth/AX8VkTwWM5TKhXLxy4Cwuc-AtxX81C6Jks5smBkTgaJpZM4Pipbm .
Away from a computer at the moment, but I suspect the problem is that you are trying to pass the codebox a tuple for the text argument where it expects a string.
So from this: easygui.codebox(msg_b, title_b, (x, ("\n"), y))
I think that the problem is that the third arg (x, ("\n"), y)
should be a string.
Try replacing it with: easygui.codebox( msg_b, title_b, str(x) + "\n" + str(y) )
And see if that works. If not I can check this later when I get my hands back on my laptop.
Actually, you're right!
I thought I'd tried every possible iteration to get this to work. Turns out I stipulated str in my code everywhere except within the easygui lines.
Thank you! Learned a lot today.
I've only been learning python for 6 weeks.
Now I can get on and implement easygui more widely in my coding practice.
Thanks again. You're a star!
On 26 September 2017 at 14:50, zadacka notifications@github.com wrote:
Away from a computer at the moment, but I suspect the problem is that you are trying to pass the codebox a tulle for the text argument where it expects a string. So from this: easygui.codebox(msg_b, title_b, (x, ("\n"), y)) I think that the problem is that the third arg (x, ("\n"), y) should be a string. Try replacing it with: easygui.codebox( msg_b, title_b, str(x) + "\n" + str(y) ) And see if that works. If not I can check this later when I get my hands back on my laptop. On Tue, Sep 26, 2017 at 14:39, fiddybux notifications@github.com wrote: Hi,
Thanks for the prompt reply.
Working in Python 3.4.2, I'm trying to count 0 and 1 characters in a short test file that looks like this, and present it in easygui:
0 00 1111
As requested, here is a code snippet. At the moment, I'm getting the error:
Exception when trying to convert <class 'tuple'> to text in self.textArea
The code:
import easygui
msg_a = ("Print file contents first (y/n)?") title_a = "Please Confirm" msg_b = ("Character count results...") title_b = "Result"
input_file = open('
', 'r') file_content = input_file.read() input_file.close() x = file_content.count('0') y = file_content.count('1')
if easygui.ynbox(msg_a, title_a): pass easygui.codebox('', '', (file_content, ("\n"), x, ("\n"), y)) else: easygui.codebox(msg_b, title_b, (x, ("\n"), y))
If I run the same code but without the easygui elements, with added print lines for x and y, it works fine.
For example:
input_file = open('
', 'r') file_content = input_file.read() input_file.close() x = file_content.count('0') y = file_content.count('1')
print("Print x:", x) print("Print y:", y)
Here, I get the expected result of 3 zero's and 4 one's, as per my test file, but naturally only within the python interpreter.
I can pass simple strings into easygui, as such ('hammer' and 'time'):
import easygui
msg_a = ("Print file contents first (y/n)?") title_a = "Please Confirm" msg_b = ("Just print hammer time...") title_b = "Result"
input_file = open('/home/russell/Dropbox/python/coding' '/01vshort.txt', 'r') file_content = input_file.read() input_file.close()
x = 'hammer' y = 'time'
if easygui.ynbox(msg_a, title_a): pass easygui.codebox('', '', (file_content, ("\n"), x, ("\n"), y)) else: easygui.codebox(msg_b, title_b, (x, ("\n"), y))
I've put about 6 hours into this today. Where am I going wrong?
Thanks.
On 25 September 2017 at 22:20, zadacka notifications@github.com wrote:
Hi @fiddybux https://github.com/fiddybux , I don't quite understand your problem.
You have a text box or a code box. You (the user) enters some value into that box. What do you want to do with the return value (the user entered value)? If you store it as a variable then you can use it within Python, or pass it through to a new box as desired. You don't have to print it to console, or lose it.
Could you provide a code segment, or additional description of the scenario, to help me understand it please?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/robertlugg/easygui/issues/130#issuecomment-332016781 , or mute the thread https://github.com/notifications/unsubscribe- auth/AX8VkTwWM5TKhXLxy4Cwuc-AtxX81C6Jks5smBkTgaJpZM4Pipbm .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub [https://github.com/ robertlugg/easygui/issues/130#issuecomment-332184954] , or mute the thread [https://github.com/notifications/unsubscribe-auth/ ADV8oWNRHciWgMIXh1D53M0iVYPA-Tcuks5smPCEgaJpZM4Pipbm] .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/robertlugg/easygui/issues/130#issuecomment-332204284, or mute the thread https://github.com/notifications/unsubscribe-auth/AX8Vke9TEC3xjWyVwcK2eyO_wOAwdo_Hks5smQEHgaJpZM4Pipbm .
No problem. I think that the issue was that: (x, ("\n"), y)
is a tuple whereas str(x) + "\n" + str(y)
is a string. A nicer way to do this might be to format your string with .format()
like: '{number_of_zeros}\n{number_of_ones}'.format(number_of_zeros=x, number_of_ones=y)
.
In any case, happy to help and hope that EasyGUI continues to be useful for you :)
Is this possible with easygui. I've been trying to find a way, but without much success yet.
All I want to do is keep the output of my py code inside easygui, without displaying results in the terminal from which the py script was invoked.
Thanks.