我有一个朋友制作的 python 代码,因为我对 python 的了解非常少。我想将它转换为 GUI,因为我们会将代码作为程序分发,以使其对初学者友好。
无论如何,这是代码:
import time, os, sys
try:
if len(sys.argv) < 2:
fn = raw_input("Enter the name of the file you want to edit: ")
else: fn = sys.argv[1]
f = open(fn)
b = f.read()
for i in b[:300]:
print hex(ord(i))[2:],
f.close()
line = str(0x15c)+'-'+str(0x15f)
if len(sys.argv)<3:
hexcode = raw_input("3 bytes color hex number: ")
else: hexcode = sys.argv[2]
if not hexcode.startswith('0x'):
hexcode = '0x'+hexcode
hexstr = '0x'
start = int(line.split('-')[0])
end = int(line.split('-')[1])
for i in b[start:end]:
hexstr+=hex(ord(i))[2:]
ascii = ''
for i in range(2,len(hexcode),2):
char = chr(int(hexcode[i:i+2],16))
ascii+=char
b = b[:start]+ascii+b[end:]
for i in b[:300]:
print hex(ord(i))[2:],
except Exception, x:
print x
time.sleep(3)
finally:
f = open(fn,'wb')
f.write(b)
f.close()
现在我在教程中找到了这个但不知道如何使用它:#simple GU0I
from Tkinter import *
root = Tk()
root.title("BreffHexReplace")
root.geometry("400x200")
app = Frame(root)
app.grid()
label = Label(app, text = "This is a label!")
label.grid()
root.mainloop()
有什么帮助吗?谢谢!
还有一件事,在这段代码中,在我输入名称或替换十六进制后,它会显示一个十六进制列表,我怎样才能让它不显示?
谢谢!