import pgzrun
WIDTH = 850
HEIGHT = 700
codes=['']
se=0
is_shift=False
et={'preserve_rgb':(0,0,0)}
letter_mapping = {
keys.A: 'a', keys.B: 'b', keys.C: 'c', keys.D: 'd',
keys.E: 'e', keys.F: 'f', keys.G: 'g', keys.H: 'h',
keys.I: 'i', keys.J: 'j', keys.K: 'k', keys.L: 'l',
keys.M: 'm', keys.N: 'n', keys.O: 'o', keys.P: 'p',
keys.Q: 'q', keys.R: 'r', keys.S: 's', keys.T: 't',
keys.U: 'u', keys.V: 'v', keys.W: 'w', keys.X: 'x',
keys.Y: 'y', keys.Z: 'z',
keys.SPACE: ' ', keys.SEMICOLON: ';',
keys.COMMA: ',', keys.PERIOD: '.',
keys.K_0: '0', keys.K_1: '1', keys.K_2: '2', keys.K_3: '3',
keys.K_4: '4', keys.K_5: '5', keys.K_6: '6', keys.K_7: '7',
keys.K_8: '8', keys.K_9: '9',
keys.COMMA: ',',keys.PERIOD: '.',
keys.SLASH: '/',keys.SEMICOLON: ';',
'keys.BRACKETLEFT': '[','keys.BRACKETRIGHT': ']',
keys.MINUS: '-',keys.QUOTE:"'",
'keys.EQUAL': '=',keys.BACKSLASH: '\\',
}
Shift_sbl={
keys.K_0: ')', keys.K_1: '!', keys.K_2: '@', keys.K_3: '#',
keys.K_4: '$', keys.K_5: '%', keys.K_6: '^', keys.K_7: '&',
keys.K_8: '*', keys.K_9: '(',
keys.COMMA: '<',keys.PERIOD: '>',
keys.SLASH: '?',keys.SEMICOLON: ':',
keys.LEFTBRACKET: "{",keys.RIGHTBRACKET: "}",
keys.MINUS: '_',keys.QUOTE:'"',
'keys.EQUAL': '+',keys.BACKSLASH: '|',
keys.A: 'A', keys.B: 'B', keys.C: 'C', keys.D: 'D',
keys.E: 'E', keys.F: 'F', keys.G: 'G', keys.H: 'H',
keys.I: 'I', keys.J: 'J', keys.K: 'K', keys.L: 'L',
keys.M: 'M', keys.N: 'N', keys.O: 'O', keys.P: 'P',
keys.Q: 'Q', keys.R: 'R', keys.S: 'S', keys.T: 'T',
keys.U: 'U', keys.V: 'V', keys.W: 'W', keys.X: 'X',
keys.Y: 'Y', keys.Z: 'Z',
}
def draw():
global output,et
screen.clear()
for i in range(len(codes)):
screen.draw.text(f'{codes[i]}',(75,i*20))
screen.draw.text(f'{se+1}->',(10,se*20))
for i in range(len(codes)-1):
screen.draw.text(str(i+1),(10,i*20))
rec=Rect((550,0),(114514,2020202))
screen.draw.filled_rect(rec,(0,0,0))
screen.draw.line((550,0),(550,850),(255,255,255))
rec=Rect((551,0),(50,30))
screen.draw.filled_rect(rec,(255,255,255) if is_shift else (0,0,0))
screen.draw.text('Shift',(551,0),color=(0,0,0))
rec=Rect((551,35),(50,30))
screen.draw.filled_rect(rec,et['preserve_rgb'])
screen.draw.text('保存!',(551,35),color=(2,0,0))
screen.draw.text('按下Shift和Enter保存',(551+50,35),color=(255,255,255))
screen.draw.text('作品名字:to_vvcode',(551+50,35*2))
screen.draw.text('当前模式:Python',(551+50,35*3))
screen.draw.text('\n\n版本V0.2',(551+50,35*3),fontsize=13,color=(128,128,128))
def update():
if et['preserve_rgb']!=(0,0,0):
et_preserve_r=et['preserve_rgb'][0]-5
et_preserve_b=et['preserve_rgb'][1]-5
et_preserve_g=et['preserve_rgb'][2]-5
et['preserve_rgb']=(et_preserve_r,et_preserve_g,et_preserve_b)
def on_key_down(key):
global codes,se,is_shift,output
if key == keys.RETURN and is_shift:
with open('to_vvcode_py.py','w') as f:
f.write('')
with open('to_vvcode_py.py','a') as f:
f.write('#文本编辑器作者:于翱睿-逐梦工作室')
for i in codes:
f.write('\n'+i)
et['preserve_rgb']=(255,255,255)
elif key==keys.RETURN:
codes.insert(se+1, '')
se+=1
elif key == 'keys.BACKSPACE':
if codes[se]!='':
codes[se]=codes[se][:-1]
elif se!=0:
codes.pop(se)
以上是一个简单的文本编辑器,可以登录复制,输入的时候可能会有点卡。同时按下shift和enter键即可保存