装X神器:HakerCoder

装X神器:HakerCoder_第1张图片

 

看了这个网站之后自己编的,时间有限,功能非常简单,要想玩还是用原来网站。

代码:

import tkinter as tk
import sys

TEXT_FONT_SIZE = 13
TEXT_FONT_NAME = "宋体"
TEXT_FG = 'green'
TEXT_BG = 'black'
OPEN_FILE_NAME = ".\\basic.txt"
TEXT_SPEED = 1
NOW_TEXT = ""
LEN = 0
IS_FULL_SCREEN = True
INFO_BAR_TEXT = "Welcome to Hakercoder[By:Cgy,Inc.2211]!!!"
DEBUG = False


def text_update(text: tk.Text, info: tk.Label):
    info.config(fg=TEXT_FG, bg=TEXT_BG, font=(TEXT_FONT_NAME, TEXT_FONT_SIZE))
    text.config(fg=TEXT_FG, bg=TEXT_BG, insertbackground=TEXT_FG, font=(TEXT_FONT_NAME, TEXT_FONT_SIZE))
    # insertbackground可以改变光标颜色
    see(text)


def update_info(info: tk.Label):
    info.config(text=INFO_BAR_TEXT + "      Keys:Esc:Exit  F11:Full Screen(or Un-full Screen)")


def openfile(info: tk.Label, text: tk.Text):
    global NOW_TEXT, LEN, INFO_BAR_TEXT
    LEN = 0
    try:
        with open(OPEN_FILE_NAME) as f_obj:
            NOW_TEXT = f_obj.read()
    except (Exception, FileNotFoundError):
        INFO_BAR_TEXT = "Error in opening files."
        update_info(info)
        see(text)


def key_passed(event: tk.Event, text: tk.Text, root: tk.Tk):
    global IS_FULL_SCREEN, LEN
    key = event.keycode
    if DEBUG:
        print("Keycode:", key)
    if key == 122:  # F11
        root.overrideredirect(False)
        IS_FULL_SCREEN = not IS_FULL_SCREEN
        root.attributes('-fullscreen', IS_FULL_SCREEN)
        see(text)
        root.overrideredirect(True)
    elif key == 27:  # Esc
        sys.exit(0)
    else:
        update(text)
        see(text)
        return "break"


def see(text: tk.Text):
    text.see(str(float(int(float(text.index('insert'))) + 2)))  # 一直显示光标所在行


def update(text: tk.Text):
    global LEN
    if DEBUG:
        print('LEN:', LEN)
    text.delete(1.0, tk.END)
    text.insert(tk.END, NOW_TEXT[:LEN + TEXT_SPEED])
    LEN += TEXT_SPEED


def main():
    root = tk.Tk()
    text = tk.Text(cursor='none')
    info = tk.Label(root, cursor='none')
    update_info(info)
    text.bind('', lambda event: key_passed(event, text, root))
    text.pack(fill=tk.BOTH, expand=True)
    info.pack(fill=tk.X)
    text.focus_set()
    openfile(info, text)
    text_update(text, info)
    root.attributes('-fullscreen', IS_FULL_SCREEN)
    root.attributes('-topmost', True)
    root.overrideredirect(True)
    root.mainloop()


if __name__ == "__main__":
    main()

没错,就是这么简单~复制粘贴好之后在同级目录下新建【basic.txt】文件,里面随便放点东西,然后运行,随便按几个键,然后,你懂的…

你可能感兴趣的:(python,python,GUI,python)