473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Console in Tkinter GUI

360monkey
Hi Bytes Community!

I am using tkinter to create a GUI and was wondering how to make a "console" widget embedded in the GUI. Sort of like the python command line but inside the GUI

Thanks in advance!
Feb 22 '10 #1
5 26245
bvdet
2,851 Expert Mod 2GB
Although I have never done it, you could make a "command line console" inside a widget with a Tkinter.Text widget.
Feb 22 '10 #2
Thanks for the suggestion, but do you know how i can store strings in a list-like format, append strings to the end as I print, and use \n\ in them? a list wont work because it would display as [..., ..., ...]
any help would be appreciated
Feb 22 '10 #3
bvdet
2,851 Expert Mod 2GB
I don't understand what you are trying to accomplish. I made a Tkinter.Text example in combination with an Entry widget. The Entry widget is bound to the Enter key and the Text widget is bound to the Insert key.
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2. from itertools import cycle
  3.  
  4. class App(Tkinter.Tk):
  5.     def __init__(self, textList, master=None):
  6.         Tkinter.Tk.__init__(self, master)
  7.         self.textiter = cycle(textList)
  8.         self.txt = Tkinter.StringVar()
  9.         self.rootEntry = Tkinter.Entry(self, textvariable=self.txt)
  10.         self.rootEntry.pack()
  11.         self.rootEntry.bind("<Return>", self.cycle_text)
  12.         self.rootText = Tkinter.Text(self)
  13.         self.rootText.pack()
  14.         self.rootText.bind("<Insert>", self.insert_all)
  15.         self.newList = []
  16.  
  17.     def cycle_text(self, arg=None):
  18.         t = self.textiter.next()
  19.         self.txt.set(t)
  20.         self.rootText.insert("end", t+"\n")
  21.         self.newList.append(self.rootText.get("end - 2 chars linestart", "end - 1 chars"))
  22.  
  23.     def insert_all(self, arg):
  24.         self.rootText.insert("end", "".join([s.strip() for s in self.newList]))
  25.  
  26. textList = ["Line 1", "Line 2", "Line 3"]
  27. root = App(textList)
  28. root.mainloop()
Feb 22 '10 #4
Thank You! This is what i was trying to achieve.
Feb 25 '10 #5
How can this be used as a command line, I just get errors like"object has no attribute 'next'", not only that, can this be used as the console for user input, I want to have the user write the user input, in the tk window instead of console, but displaying console in tk window could work to.
Mar 18 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas Buschhardt | last post by:
Hallo, I have a problem with Tkinter and the module socket. In a console-window everything works fine, but in a Tkinter-window I can no more use the widgets. I found some other mails with this...
3
by: Bob Greschke | last post by:
I have a program where the user pushes a button, a "starting" message is ..inserted to a text field with an associated scroll bar, a thread is started that inserts a "working..." message on to the...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
0
by: srinathava | last post by:
Hi, I am trying to run a Tkinter application in a thread and it works pretty well to an extent. However, when I try to recreate the application after the thread exits, the new application never...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
4
by: Kevin Walzer | last post by:
I'm trying to manage user preferences in a Tkinter application by initializing some values that can then be configured from a GUI. The values are set up as a dict, like so: self.prefs= {...
2
by: beginner | last post by:
Hi everyone, I have a question about Tkinter programs. What I want is a GUI window along with an interpreter window, so that I can do things by clicking on the GUI or typing commands in the...
5
by: msunderwd | last post by:
Having a problem with "compiling" a Tkinter/python program using py2exe (and pyinstaller, for that matter)... I have several dialogs that are derived from the tkSimpleDialog.Dialog class. These...
4
by: MartinRinehart | last post by:
Everything I've read about Tkinter says you create your window and then call its mainloop() method. But that's not really true. This is enough to launch a default window from the console: ...
1
by: Alex Bryan | last post by:
I know this is possible so someone out there should be able to help me! Okay, I have a program that uses Tkinter, and BeautifulSoup. I don't think it should be a problem. I want to create an exe of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.