Advertisement
Guest User

Untitled

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