I’m a beginner in python and i need help with a personnal project.
As written in the title, I want to recreate the python terminal. let me explain:
When I create code, I prefer it to be visibly nice in the pycharm’s terminal, created a tkinter interface it’s sometimes boring…
example of one of my minimalist but pleasant to read code (yes, it’s in frensh
so i just want the same thing but in a simple tkinter interface.
I recreated the “print()” command
“DBoxComputer()” when it is the computer, a ‘print()’ (in white on the image above)
“DBoxUser()” when it’s me who enters an ‘input()’ (in green on the image above)
The problem, impossible for me to recreate the “input()” command
I can’t pause my code. Tell it to wait until I press “return” (there is a key bind) to move on, like in the classic terminal when it waits for an “input()” then “return”
import tkinter.font as font
import ttkbootstrap as ttk
#-PARAMETRES FENETRES-
root = ttk.Window(themename="darkly")
root.title("test")
root.geometry("800x500+50+50")
#-FONCTIONS
def DBoxComputer(entry):
DBox.config(state="normal")
DBox.insert("end-1c", entry + "n", "ComputerBasic")
DBox.config(state="disabled")
DBox.yview_moveto('1.0')
def DBoxUser(entry):
DBox.config(state="normal")
DBox.insert("end-1c", entry + "n", "UserBasic")
DBox.config(state="disabled")
myEntry.delete(0, ttk.END)
def Entry():
x = ""
while x != "Return":
root.bind("<Key>", Raccourcies)
user = myEntry.get()
DBoxUser(user)
return user
def Raccourcies(event):
x = event.keysym
print(x)
if x == "Return":
return x
def Start():
DBoxComputer("Hello Patrick")
DBoxComputer("Do you like biscuits ?")
x = Entry()
if x == "yes":
DBoxComputer("Haaa me too, miam :p")
elif x == "no":
DBoxComputer("Non ?! Sad... you're missing a few things...")
else:
DBoxComputer("You don't know how to answer a simple question?")
#-Raccourcies-
root.bind("<Key>", Raccourcies)
#-WIDGETS-
marge = ttk.Label(root) #deco
DBox = ttk.Text(marge, font="georgia 10", state="disabled", width=80)
espace = ttk.Frame(marge) #deco
myEntry = ttk.Entry(marge, width=80)
#-FONT CUSTOMS-
DBox.tag_config("ComputerBasic", font=font.Font(family="System", size=20, weight="normal", slant="italic"))
DBox.tag_config("UserBasic", font=font.Font(family="Microsoft Sans Serif", size=20, weight="normal"))
#-PLACEMENTS-
marge.pack(padx=10, pady=10, expand=True)
DBox.pack(expand=True)
espace.pack(pady=5)
myEntry.pack()
Start()
#-BOUCLE-
root.mainloop()
if i delete these lines:
x = Entry()
if x == "yes":
DBoxComputer("Haaa me too, miam :p")
elif x == "no":
DBoxComputer("Non ?! Sad... you're missing a few things...")
else:
DBoxComputer("You don't know how to answer a simple question?")
this appears:
.
I’m sure the problem comes from the fact that it waits for me to press “return” but the loop goes so fast that it isn’t even able to launch the program
Do you have a solution, whether in the structure of the code, or a method that I don’t know?
Thanks in advance
Jack Panot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.