0

私は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()

何か助けはありますか?ありがとう!

また、もう1つ、このコードでは、名前またはreplacor hex を入力した後、 hex のリストが表示されますが、表示されないようにするにはどうすればよいですか?

ありがとう!

4

1 に答える 1

0

Because this program is so simple, you can try EasyGui( easygui.sourceforge.net/ ). To start, add import easygui as eg. This line loads the EasyGui module. Next, replace fn = raw_input("Enter the name of the file you want to edit: ") with fn = eg.fileopenbox(title = 'HexReplace', msg = 'Browse to the file you wish to edit'). This opens a box to browse to the wanted file. Also replace hexcode = raw_input("3 bytes color hex number: ") with hexcode = eg.enterbox(msg = '3 bytes color hex number', title = 'HexReplace'). This pops up an input box. Replace print x with eg.msgbox(title = 'HexReplace', msg = x). This shows a message box with the exception. The title argument is the window title. To remove the hex list, add between the imports and the try block: null = open(os.devnull, 'W's); oldstdout = system.stdout; sys.stdout = null This will silence all print messages.

于 2013-04-06T20:22:33.920 に答える