Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- WLC = """
- PyTerminal - 0.0.1
- pt.help | pt.github
- """
- class pt:
- help = 'some help!'
- github = 'github link'
- class Gui:
- def __init__(self, root):
- self.Space = 70 # space between >>> and second >>>, ideal: 70
- self.root = root
- root.geometry('700x400')
- root.title('PyTerminal')
- root.configure(background='black')
- root.option_add('*font', 'calibri 12')
- Label(root, text=WLC, fg='light blue', bg='black').place(x=0, y=0)
- ent = self._in(0, 70, 30, 72) # first >>>, numbers in format: x1, y1, x2, y2
- ent.bind("<Return>", (lambda event: self.processcmd(ent)))
- def processcmd(self, cmd):
- self.Space += 60 # add gap, ideal: 60
- cmd.unbind('<Return>')
- return self._out(0, self.Space-30, cmd.get())
- def _in(self, sx, sy, cx, cy):
- Label(self.root, text=f'>>>', fg='dark grey', bg='black').place(x=sx, y=sy)
- cmd = Entry(self.root, bg='black', fg='white', borderwidth=0, width=500, insertbackground='white')
- cmd.place(x=cx, y=cy)
- return cmd
- def _out(self, x, y, cmd):
- To_Deduct = 0
- try:
- Label(self.root, text=eval(cmd), fg='white', bg='black').place(x=x, y=y)
- except:
- try:
- exec(cmd, globals())
- To_Deduct = 30
- except Exception as e:
- Label(self.root, text=e, fg='red', bg='black').place(x=x, y=y-To_Deduct)
- entry = self._in(0, self.Space-To_Deduct, 30, (self.Space + 2)-To_Deduct)
- entry.bind("<Return>", (lambda event: self.processcmd(entry)))
- if To_Deduct:
- self.Space -= 30 # remove some space in case theres anything to deduct (no "empty" rows"), ideal: 30
- return 'OK'
- gui = Gui(Tk())
- class ModifiedPrint:
- def __init__(self):
- self.old = sys.stdout
- def write(self, text):
- sys.stdout = self.old
- Label(gui.root, text=text, fg='white', bg='black').place(x=0, y=gui.Space-30)
- sys.stdout = self
- def flush(self):
- self.old.flush()
- sys.stdout = ModifiedPrint()
- gui.root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment