•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 403,366 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,337 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1025 | Replies: 16
![]() |
Alright, I'm trying to make a small GUI application that'll allow me to run a .ck file (with ChucK) from a GUI, from a preset directory.
Okay, so I have:
In the
But, what I really need it to do is store the text in the entry field into a variable (x), then call the shell command
Can anyone help me?
Thank you in advance!
Okay, so I have:
python Syntax (Toggle Plain Text)
from Tkinter import * class chuckrun: def __init__(self, master): ui = Frame(master) ui.pack() self.file = Entry(ui, text="Filename") self.file.pack(side=LEFT) self.play = Button(ui, text="Play", command=playCk) self.play.pack(side=RIGHT) def playCk(self): p = os.popen('chuck') # run chuck $HOME/Apps/Source/ChucK/Filename # (from the Entry field above) root = Tk() app = chuckrun(root) root.mainloop()
In the
def playCk(self) part, I have no idea what to do. What I want it to do is to run the command chuck $HOME/Apps/Source/ChucK/filename where filename is the filename specified in the Entry field above (as stated in the comment).But, what I really need it to do is store the text in the entry field into a variable (x), then call the shell command
chuck $HOME/Apps/Source/ChucK/x. But I have no idea how to use variables, say from Python to the shell and vice versa.Can anyone help me?
Thank you in advance!
Last edited by linux : Mar 7th, 2008 at 9:57 pm.
Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
•
•
Join Date: Dec 2006
Posts: 408
Reputation:
Rep Power: 2
Solved Threads: 56
You will likely want to use a Tkinter StringVar() with the .get() to get the contents of the entry box. If memory serves - a Google for "Tkinter StringVar Entry" will yield thousands of hits as well
var = Tkinter.StringVar()
entry_box = Tkinter.Entry(frame_name, width=5, textvariable=var)
python_var=var.get() [Under def playCk(self): for your app]
http://infohost.nmt.edu/tcc/help/pub...variables.html
You can run the command using os.system() or subprocess.
os.system("chuck $HOME/Apps/Source/ChucK/" + python_var)
var = Tkinter.StringVar()
entry_box = Tkinter.Entry(frame_name, width=5, textvariable=var)
python_var=var.get() [Under def playCk(self): for your app]
http://infohost.nmt.edu/tcc/help/pub...variables.html
You can run the command using os.system() or subprocess.
os.system("chuck $HOME/Apps/Source/ChucK/" + python_var)
Last edited by woooee : Mar 7th, 2008 at 10:57 pm.
Solved, but not totally:
It shows the GUI, and I input
My full code for this is:
EDIT: By the way, will:
Actually kill the shell command?
alex@alex-laptop:~/Apps/Source/Python Source$ python chuckrun.py
Exception in Tkinter callback
Traceback (most recent call last):
File "lib-tk/Tkinter.py", line 1406, in __call__
return self.func(*args)
File "chuckrun.py", line 11, in playCk
os.system("chuck $HOME/Apps/Source/ChucK/" + filename)
TypeError: cannot concatenate 'str' and 'instance' objectsIt shows the GUI, and I input
foo.ck, and I get that error.My full code for this is:
python Syntax (Toggle Plain Text)
from Tkinter import * import os class chuckrun: def __init__(self, master): filename = StringVar() def playCk(): os.system("chuck $HOME/Apps/Source/ChucK/" + filename) ui = Frame(master) ui.pack() self.file = Entry(ui, text="Filename", textvariable=filename) self.file.pack(side=LEFT) self.play = Button(ui, text="Play", command=playCk) self.play.pack(side=RIGHT) root = Tk() app = chuckrun(root) root.mainloop()
EDIT: By the way, will:
python Syntax (Toggle Plain Text)
def stopCk(): os.system("^C")
Actually kill the shell command?
Last edited by linux : Mar 7th, 2008 at 11:36 pm.
Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
python Syntax (Toggle Plain Text)
from Tkinter import * import os class chuckrun: def __init__(self, master): filename=StringVar() def playCk(): os.system("chuck " + str(filename)) ui = Frame(master) ui.pack() # Text entry for gathering filename self.file = Entry(ui) self.file.pack(side=LEFT) # Play button for executing the file self.play = Button(ui, text="Play", command=playCk) self.play.pack(side=LEFT) # Kills the application self.close = Button(ui, text="Close", command=ui.quit) self.close.pack(side=LEFT) root = Tk() root.title("ChucK") app = chuckrun(root) root.mainloop()
I have that so far. However, it seems to be completely ignoring whatever the user puts in the textbox. What am I doing wrong?
Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
•
•
Join Date: Dec 2006
Posts: 408
Reputation:
Rep Power: 2
Solved Threads: 56
Python variables are different from Tkinter variables. You have to use .get
def playCk():
python_var=filename.get()
os.system("chuck " + python_var)alex@alex-laptop:~/Apps/Source/Python Source$ python chuckrun.py
File "chuckrun.py", line 9
def playCk():
^
IndentationError: unexpected indent
alex@alex-laptop:~/Apps/Source/Python Source$ python Syntax (Toggle Plain Text)
#!/usr/bin/python/ from Tkinter import * import os class chuckrun: def __init__(self, master): filename=StringVar() def playCk(): python_var=filename.get() os.system("chuck " + python_var) ui = Frame(master) ui.pack() # Text entry for gathering filename self.file = Entry(ui) self.file.pack(side=LEFT) # Play button for executing the file self.play = Button(ui, text="Play", command=playCk()) self.play.pack(side=LEFT) # Kills the application self.close = Button(ui, text="Close", command=ui.quit) self.close.pack(side=LEFT) root = Tk() root.title("ChucK") app = chuckrun(root) root.mainloop()
That error doesn't seem logical to me. My indent seems to be in the right place, isn't it?
Last edited by linux : Mar 8th, 2008 at 1:17 pm.
Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
•
•
Join Date: Dec 2006
Posts: 408
Reputation:
Rep Power: 2
Solved Threads: 56
We all have programs that are out to get us. This one is yours. See anything unusual here When you can't find a problem on the line of the error, look at the previous line as well.
def __init__(self, master):
filename=StringVar()
def playCk(): Last edited by woooee : Mar 8th, 2008 at 2:29 pm.
I actually indented the
filename=StringVar() over one more, and it executes fine. However, it issues the chuck command before the user enters the information and says chuck: No input files. How can I make it wait? Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Using OpenGL in Visual C++: Part I (Game Development)
- calling command prompt with VB.NET (VB.NET)
- Interpreting a script line by line (Shell Scripting)
- opening programs (C++)
- Closing external application (VB.NET)
- Making a UNIX Shell, so inexperienced at it (C++)
- Can this program be written? (C)
- i want help about the Simulate a Linux/UNIX shell, called MASH in the C (C)
Other Threads in the Python Forum
- Previous Thread: dynamically generating buttons and events
- Next Thread: How to sort word (from file) frequancy in decrease order? I need help


Linear Mode