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!
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.
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
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. - import Tkinter
-
from itertools import cycle
-
-
class App(Tkinter.Tk):
-
def __init__(self, textList, master=None):
-
Tkinter.Tk.__init__(self, master)
-
self.textiter = cycle(textList)
-
self.txt = Tkinter.StringVar()
-
self.rootEntry = Tkinter.Entry(self, textvariable=self.txt)
-
self.rootEntry.pack()
-
self.rootEntry.bind("<Return>", self.cycle_text)
-
self.rootText = Tkinter.Text(self)
-
self.rootText.pack()
-
self.rootText.bind("<Insert>", self.insert_all)
-
self.newList = []
-
-
def cycle_text(self, arg=None):
-
t = self.textiter.next()
-
self.txt.set(t)
-
self.rootText.insert("end", t+"\n")
-
self.newList.append(self.rootText.get("end - 2 chars linestart", "end - 1 chars"))
-
-
def insert_all(self, arg):
-
self.rootText.insert("end", "".join([s.strip() for s in self.newList]))
-
-
textList = ["Line 1", "Line 2", "Line 3"]
-
root = App(textList)
-
root.mainloop()
Thank You! This is what i was trying to achieve.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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:
...
|
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...
|
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...
|
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= {...
|
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...
|
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...
|
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:
...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
| |