Lookslikerain75
Posts: 13
Joined: Wed Jul 17, 2019 6:29 pm

GUIZERO - input_box = TextBox

Fri Oct 11, 2019 9:36 am

I setup an input_box = textbox (example below) in three actions if a button is pressed a command runs and a log file is created then used as the contents of the textbox. If the second button is pressed a different log becomes the content of the text box. unless i am going mad this was working. the same text box displayed different log files depending which button was pressed.

I must have changed something or imagined it was working as now when the second button is pressed which ever one that maybe a second textbox is displayed below the first one and does not replace the first one, so i end up with an new textbox every time i press a button.

I am pretty sure i have gone about this the wrong way, the idea is to have one text box that displays different log files after a button is pressed a custom command run by myCmd and the resulting log shown. I am not great at coding as you can see, any ideas welcome.

Code: Select all

#!/usr/bin/env python3

from guizero import App, Text, PushButton, info, TextBox
import os 
# Method to call when button pressed
myCmd= '<command> > /home/pi/log.log'
myCmd2= '<command> > /home/pi/log1.log'
myCmd3= '<command> > /home/pi/log2.log'
# Set up the app
app = App(title="Command and log", height="600", width="600")

def action():
    os.system(myCmd)
    file = open("/home/pi/log.log","r+").read()
    input_box = TextBox(app, text=file, height=20, width=70, multiline=True)
    textshow.value = "Complete"

def action2():
    os.system(myCmd2)
    file1 = open("/home/pi/log1.log","r+").read()
    input_box = TextBox(app, text=file1, height=20, width=70, multiline=True)
    textshow.value = "Complete"

def action3():
    os.system(myCmd3)
    file2 = open("/home/pi/log2.log","r+").read()
    input_box = TextBox(app, text=file2, height=20, width=70, multiline=True)
    textshow.value = "Complete"
 
Text(app, "Current Version " + os.uname()[2], align="bottom")
button = PushButton(app, action, text="Command 1", align="top")
button = PushButton(app, action2, text="Command 2", align="top")
button = PushButton(app, action3, text="Command 3", align="bottom")
textshow = Text(app, text="--", color="green", align="bottom")

app.display()

Lookslikerain75
Posts: 13
Joined: Wed Jul 17, 2019 6:29 pm

Re: GUIZERO - input_box = TextBox

Fri Oct 11, 2019 12:54 pm

I have just changed the coed to open the log file in leafpad instead. but may come back to this another time

User avatar
joelostinspace
Posts: 103
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: GUIZERO - input_box = TextBox

Fri Oct 11, 2019 4:13 pm

it works for me,
I didn't need- :
os.system(myCmd)
the only thing i see is you need to clear the previous log they get stacked,
Create a text box with buttons and use the function to add content...
I haven't spent much time w/ quizero seems the set is depreciated:
good luck,
joe

Code: Select all

from guizero import App, Text, PushButton, info, TextBox
import os 
# Method to call when button pressed
myCmd= '<command> > /home/pi/log.log'
myCmd2= '<command> > /home/pi/log1.log'
myCmd3= '<command> > /home/pi/log2.log'
# Set up the app
app = App(title="Command and log", height="600", width="600")

def action():
    input_box.clear()
    file = open("/home/pi/log.log","r+").read()
    input_box.set(file)  
    
    textshow.value = "Complete"

def action2():
    input_box.clear()
    file = open("/home/pi/log1.log","r+").read()
    input_box.set(file)  
    
    textshow.value = "Complete"

def action3():
    input_box.clear()
    file = open("/home/pi/log2.log","r+").read()
    input_box.set(file)  
    
    textshow.value = "Complete"
 
Text(app, "Current Version " + os.uname()[2], align="bottom")
button = PushButton(app, action, text="Command 1", align="top")
button = PushButton(app, action2, text="Command 2", align="top")
button = PushButton(app, action3, text="Command 3", align="bottom")
input_box = TextBox(app, text='place holder', height=20, width=70,
                        multiline=True, )
textshow = Text(app, text="--", color="green", align="bottom")

app.display()

To travel is to discover that everyone is wrong about other countries.


--- Aldous Huxley

User avatar
lawsie
Posts: 15
Joined: Thu Jul 17, 2014 6:02 pm

Re: GUIZERO - input_box = TextBox

Mon Oct 14, 2019 1:26 pm

joelostinspace is right - set is deprecated and has been for a really long time. Use `input_box.value = file` (docs page here - https://lawsie.github.io/guizero/textbox/). :)

User avatar
joelostinspace
Posts: 103
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: GUIZERO - input_box = TextBox

Mon Oct 14, 2019 3:32 pm

@lawsie hey thanks for the module and great documentation spent last weekend making apps. Really like that you made all the labels textvariables. Joe

To travel is to discover that everyone is wrong about other countries.


--- Aldous Huxley

Return to “Python”