Guest User

Untitled

a guest
May 31st, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. from tkinter import *
  2.  
  3.  
  4. WLC = """
  5. PyTerminal - 0.0.1
  6. pt.help | pt.github
  7. """
  8.  
  9. class pt:
  10.     help = 'some help!'
  11.     github = 'github link'
  12.  
  13.  
  14. class Gui:
  15.     def __init__(self, root):
  16.         self.Space = 70  # space between >>> and second >>>, ideal: 70
  17.         self.root = root
  18.  
  19.         root.geometry('700x400')
  20.         root.title('PyTerminal')
  21.         root.configure(background='black')
  22.         root.option_add('*font', 'calibri 12')
  23.  
  24.         Label(root, text=WLC, fg='light blue', bg='black').place(x=0, y=0)
  25.  
  26.         ent = self._in(0, 70, 30, 72)  # first >>>, numbers in format: x1, y1, x2, y2
  27.         ent.bind("<Return>", (lambda event: self.processcmd(ent)))
  28.  
  29.     def processcmd(self, cmd):
  30.         self.Space += 60  # add gap, ideal: 60
  31.         cmd.unbind('<Return>')
  32.  
  33.         return self._out(0, self.Space-30, cmd.get())
  34.  
  35.     def _in(self, sx, sy, cx, cy):
  36.         Label(self.root, text=f'>>>', fg='dark grey', bg='black').place(x=sx, y=sy)
  37.         cmd = Entry(self.root, bg='black', fg='white', borderwidth=0, width=500, insertbackground='white')
  38.         cmd.place(x=cx, y=cy)
  39.         return cmd
  40.  
  41.     def _out(self, x, y, cmd):
  42.         To_Deduct = 0
  43.         try:
  44.             Label(self.root, text=eval(cmd), fg='white', bg='black').place(x=x, y=y)
  45.         except:
  46.             try:
  47.                 exec(cmd, globals())
  48.                 To_Deduct = 30
  49.             except Exception as e:
  50.                 Label(self.root, text=e, fg='red', bg='black').place(x=x, y=y-To_Deduct)
  51.  
  52.         entry = self._in(0, self.Space-To_Deduct, 30, (self.Space + 2)-To_Deduct)
  53.         entry.bind("<Return>", (lambda event: self.processcmd(entry)))
  54.  
  55.         if To_Deduct:
  56.             self.Space -= 30  # remove some space in case theres anything to deduct (no "empty" rows"), ideal: 30
  57.         return 'OK'
  58.  
  59. gui = Gui(Tk())
  60.  
  61. class ModifiedPrint:
  62.     def __init__(self):
  63.         self.old = sys.stdout
  64.  
  65.     def write(self, text):
  66.         sys.stdout = self.old
  67.         Label(gui.root, text=text, fg='white', bg='black').place(x=0, y=gui.Space-30)
  68.         sys.stdout = self
  69.  
  70.     def flush(self):
  71.         self.old.flush()
  72.  
  73.  
  74. sys.stdout = ModifiedPrint()
  75.  
  76. gui.root.mainloop()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment