Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi, i want to make a GUI Program using python, in this program i want to display the value from print at the console to my GUI.

for example, i create one file to execute this code.
this file name is increment_tets.py

import os
import time
import sys


def increment():
    
    for i in range (0,100):
        if(i%10==0):
            print(i)
            time.sleep(1.0)



from this code it would display on console like this.

==================== RESTART: /home/pi/increment_test.py ====================
0
10
20
30
40
50
60
70
80
90
>>> 



i wanna display that output to GUI so i wrote my gui program file name is increment_gui.py. It will display the data from console after the icrement loop was finished.my Question is what should i do if i wanna display one by one of the data from the console to my gui program??

What I have tried:

This is my gui program


from guizero import App, Combo,Text,CheckBox, ButtonGroup,PushButton,info,TextBox, Picture
import os
import time
import sys

from io import StringIO



     
def counter_loop():
   import increment_test
    
   old_stdout = sys.stdout
 
# This variable will store everything that is sent to the standard output
 
   result = StringIO()
 
   sys.stdout = result
   increment_test.increment()
    #sys.stdout = old_stdout
   result_string = result.getvalue()
   counter.value = result_string # read output
        
   button.disable()
        
   

        

app = App(title="get data", width=1000, height=1000,)
counter = Text(app, size = 20, font = "Times New Roman", color="black")
button = PushButton(app, command=counter_loop, text = "Display your name")



    





app.display()



and the result from this program is like this
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900