By Qlbox via Discussions on Python.org at 30Mar2022 14:49:
Hi guys im begginer in programming and want to make a code editor (i
know it bad idea)
It isn’t a bad idea, but many already exist and it is a large project if
you intend to end up with a serious IDE-like editor). But an excellent
learning exercise, and you can end up with useful things you can use
elsewhere even if the editor itself is never complete.
my code:
Tip: enclose code between triple backticks:
your code here
I get to see it ok because I’m on email preferring plain text, but I
gather others do not see the indentation.
I’ll recite your code below so others can see it nicely indented.
You wrote:
and im have and errors:
TypeError: Text.get() missing 1 required positional argument: 'index1'
It helps to include the whole traceback - it tells us the line number if
nothing else, and for other errors the full listing can be helpful.
You have this:
code = codeInput.get()
where codeInput
is a Tk Text
widget. The docs for that widget start
here: 24. The Text widget
and the methods available are listed here:
24.8. Methods on Text widgets
The .get()
method requires a starting point. You didn’t supply one.
These can take a few forms because text widgets suppose marks and
things, but just passing 0
is a good start. Try that and see what you
get.
Also, you write:
index = code.startswith("print\"")
if index == True:
index
is a Boolean value. You can just use these directly, much as you
might in English prose:
index = code.startswith("print\"")
if index:
without the cumbersome explicit test against True
. And for falsehood
you’d write:
if not index:
Cheers,
Cameron Simpson cs@cskk.id.au
For reference, your code below, indentation preserved:
from tkinter import *
from time import sleep
from random import randint
root = Tk()
def run():
global codeInput
code = codeInput.get()
index = code.startswith("print\"")
if index == True:
index = code.find("\"")
print(index)
codeInput = Text(root, width = 500, height = 50, bg = 'silver')
codeInput.pack()
run = Button(root, text = "RUN", command = run)
run.pack()
root.mainloop()