求赞!!!
代码:
# -*- coding: utf-8 -*-
import tkinter as tk
import os
import time
class MyTerminal(tk.Tk):
def __init__(self):
super().__init__()
self.title("My Terminal")
self.geometry("800x600")
self.create_widgets()
self.create_command()
self.create_login()
def create_widgets(self):
self.command_label = tk.Label(self, text="Command:")
self.command_label.pack(side="left")
self.command_entry = tk.Entry(self)
self.command_entry.pack(side="left", fill="x", expand=True)
self.command_button = tk.Button(self, text="Execute", command=self.execute_command)
self.command_button.pack(side="left")
self.command_output = tk.Text(self)
self.command_output.pack(fill="both", expand=True)
def create_command(self):
self.command = ""
def create_login(self):
self.login_label = tk.Label(self, text="Login:")
self.login_label.pack(side="left")
self.login_entry = tk.Entry(self)
self.login_entry.pack(side="left", fill="x", expand=True)
self.login_button = tk.Button(self, text="Login", command=self.login)
self.login_button.pack(side="left")
def execute_command(self):
self.command = self.command_entry.get()
self.command_entry.delete(0, "end")
if self.command == "exit":
self.destroy()
elif self.command == "clear":
self.command_output.delete("1.0", "end")
elif self.command == "help":
self.command_output.insert("end", "Available commands: exit, clear, help\n")
else:
output = os.popen(self.command).read()
self.command_output.insert("end", output)
def login(self):
self.username = self.login_entry.get()
self.login_entry.delete(0, "end")
self.command_output.insert("end", "Welcome, " + self.username + "\n")
if __name__ == "__main__":
terminal = MyTerminal()
terminal.mainloop()
未经作者允许,请不要转载!!!
作者:Tu_Junkai
想转载请私信作者!!!
转载时请标注原文链接!!!