View Full Version : [SOLVED] Help with Zenity in Python
Datweakfreak
February 6th, 2011, 11:28 AM
The following piece of code in a bash script:
g='abc'
zenity --info --text="$g"
returns the value of g, that is 'abc', in a zenity dialog box.
Its equivalent in Python:
import os
g='abc'
os.system('zenity --info --text="$g"')
This doesn't return 'abc', though. It just shows an empty dialog box.
Is there any other equivalent for '$g' in Python?
kimet
February 6th, 2011, 01:18 PM
Bash can't know who is 'g'. Put inside os.system:
import os
os.system('g="abc"; zenity --info --text="$g"')
Or try another toolkit, ex.Tkinder
from Tkinter import *
g='abc'
w = Label(text= g)
w.pack()
mainloop()
MadCow108
February 6th, 2011, 01:22 PM
you might want to use pyzenity:
http://pypi.python.org/pypi/PyZenity/0.1.1/
though I never used it.
to do it directly subprocess is usually preferable to os.system:
import subprocess
g="a bc"
subprocess.call(["zenity", "--info", "--text", g])
Datweakfreak
February 7th, 2011, 01:57 AM
Bash can't know who is 'g'. Put inside os.system:
import os
os.system('g="abc"; zenity --info --text="$g"')
That worked!
I'll try out the other suggestions too, just for the learning cause.
Thanks, guys! :p
Miyavix3
February 7th, 2011, 06:30 AM
You could always use a string formatter.
import os
var = "This is an info box"
os.system("zenity --info --text=%s" %(var))
Seems a little bit easier.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.