저는 파이썬에서 GUI로 일부 작업을하고 있습니다. Tkinter 라이브러리를 사용하고 있습니다. 지금은 조립하는 방법을 모르는tkinter 이벤트에 어떻게 응답합니까?
from Tkinter import *
import tkFileDialog,Tkconstants,collections
root = Tk()
root.title("TEST")
root.geometry("800x600")
button_opt = {'fill': Tkconstants.BOTH, 'padx': 66, 'pady': 5}
fileName = ''
def openFile():
fileName = tkFileDialog.askopenfile(parent=root,title="Open .txt file", filetypes=[("txt file",".txt"),("All files",".*")])
Button(root, text = 'Open .txt file', fg = 'black', command= openFile).pack(**button_opt)
frequencies = collections.defaultdict(int) # <-----------------------
with open("test.txt") as f_in:
for line in f_in:
for char in line:
frequencies[char] += 1
total = float(sum(frequencies.values())) #<-------------------------
root.mainloop()
: 나는 시작
frequencies = collections.defaultdict(int) # <-----------------------
with open("test.txt") as f_in:
for line in f_in:
for char in line:
frequencies[char] += 1
total = float(sum(frequencies.values())) #<-------------------------
:
나는이 .txt 파일을 열고 처리의이 비트를 할 것입니다 버튼을, 필요 내 코드 그래서 버튼을 누르면 실행됩니다.
많은 도움;) 도움을 청합니다 – thaking
3 분 후에 외쳐야합니다. +1 좋은 답변, 훨씬 덜 복잡합니다. – John