Написал программу которая в файлике берет все даті записанніе разніми форматами и приводит к одному виду. Она вот вроде бы и работает, но проблема в слеудующем. Когда запускаю компилятор (PyCharm) то форма сначала открывается и все кнопки отображаются но если нажать кнопку Do me!(это функция but_clicked) то программа зависает и не отвечает. Пожалуйста помогите решить;)
from Tkinter import *
from enum import Enum
import os
import tkFileDialog
import enum
ru=lambda x: x.decode('utf-8')
def Quit(ev):
root.quit()
def LoadFile(ev):
fn = tkFileDialog.Open(root, filetypes = [('*.txt files', '.txt')]).show()
if fn == '':
return
textbox.delete('1.0', 'end')
textbox.insert('1.0', open(fn, 'rt').read())
def SaveFile(ev):
fn = tkFileDialog.SaveAs(root, filetypes = [('*.txt files', '.txt')]).show()
if fn == '':
return
if not fn.endswith(".txt"):
fn+=".txt"
open(fn, 'wt').write(textbox.get('1.0', 'end'))
def but_clicked(self):
in_file1="C:\\proga_mego\\main\\in_file.txt"
out_file1="C:\\proga_mego\\main\\out_file.txt"
in_file = open(in_file1,'r')
out_file = open(out_file1,'w')
hislo = ('1','2','3','4','5','6','7','8','9','0')
EDate = (' ','.')
Raz = ('.','-','/')
State = enum.Enum
('start', 'X', 'XX','X.', 'X.X', 'X.X.', 'X.X.X', 'XXX', 'XXXX',
'XXXX.', 'XXXX.X', 'XXXX.XX', 'XXXX.XX.', 'XXXX.XX.X', 'XXXX.XX.XX',
'X.X.XX', 'X.X.XXX', 'X.X.XXXX', 'XX.', 'XX.X', 'XX.XX', 'XX.XX.',
'XX.XX.X', 'XX.XX.XX', 'XX.XX.XXX', 'XX.XX.XXXX')
state= 'start'
while True:
f= in_file.read(1)
out_file.write(f)
if f == '\n':
break
elif state=='start':
if f in hislo:
state='X'
else:
state= 'start'
elif state=='X':
if f in hislo:
state='XX'
elif f in Raz:
state='X.'
else:
state= 'start'
elif state=='XX':
if f in hislo:
state='XXX'
elif f in Raz:
state="XX."
else:
state= 'start'
elif state =='X.':
if f in hislo:
state='X.X'
else:
state= 'start'
elif state =='X.X':
if f in Raz:
state='X.X.'
else:
state= 'start'
elif state =='X.X.':
if f in hislo:
state='X.X.X'
else:
state= 'start'
elif state =='X.X.X':
if f in hislo:
state='X.X.XX'
else:
state= 'start'
elif state =='XXX':
if f in hislo:
state='XXXX'
else:
state= 'start'
elif state =='XXXX':
if f in Raz:
state='XXXX.'
else:
state='start'
elif state =='XXXX.':
if f in hislo:
state='XXXX.X'
else:
state='start'
elif state =='XXXX.X':
if f in hislo:
state='XXXX.XX'
else:
state='start'
elif state =='XXXX.XX':
if f in Raz:
state='XXXX.XX.'
else:
state='start'
elif state =='XXXX.XX.':
if f in hislo:
state='XXXX.XX.X'
else:
state='start'
elif state =='XXXX.XX.X':
if f in hislo:
state='XXXX.XX.XX'
else:
state='start'
elif state =='XXXX.XX.XX':
if f in EDate:
out_file.seek(-11, 1)
in_file.seek(-3, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(-5, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(-7, 1)
v= in_file.read(4)
out_file.write(v)
in_file.seek(6, 1)
state='start'
else:
state='start'
elif state =='X.X.XX':
if f in EDate:
out_file.seek(-7, 1)
in_file.seek(-7, 1)
v= in_file.read(1)
out_file.write('0')
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(1)
out_file.write('0')
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(2)
out_file.write('19')
out_file.write(v)
state='start'
elif f in hislo:
state='X.X.XXX'
else:
state='start'
elif state =='X.X.XXX':
if f in hislo:
state='X.X.XXXX'
else:
state='start'
elif state =='X.X.XXXX':
if f in EDate:
out_file.seek(-9, 1)
in_file.seek(-9, 1)
v= in_file.read(1)
out_file.write('0')
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(1)
out_file.write('0')
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(4)
out_file.write(v)
state='start'
else:
state='start'
elif state =='XX.':
if f in hislo:
state='XX.X'
else:
state='start'
elif state =='XX.X':
if f in hislo:
state='XX.XX'
else:
state='start'
elif state =='XX.XX':
if f in Raz:
state='XX.XX.'
else:
state='start'
elif state =='XX.XX.':
if f in hislo:
state='XX.XX.X'
else:
state='start'
elif state =='XX.XX.X':
if f in hislo:
state='XX.XX.XX'
else:
state='start'
elif state =='XX.XX.XX':
if f in hislo:
state='XX.XX.XXX'
elif f in EDate:
out_file.seek(-9, 1)
in_file.seek(-9, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
out_file.write('19')
v= in_file.read(2)
out_file.write(v)
state='start'
else:
state='start'
elif state =='XX.XX.XXX':
if f in hislo:
state='XX.XX.XXXX'
else:
state='start'
elif state =='XX.XX.XXXX':
if f in EDate:
out_file.seek(-11, 1)
in_file.seek(-11, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(2)
out_file.write(v)
out_file.write('.')
in_file.seek(1, 1)
v= in_file.read(4)
out_file.write(v)
state='start'
else:
state='start'
else:
pass
in_file.close()
out_file.close()
root = Tk()
panelFrame = Frame(root, height = 60, bg = 'gray')
textFrame = Frame(root, height = 340, width = 600)
panelFrame.pack(side = 'top', fill = 'x')
textFrame.pack(side = 'bottom', fill = 'both', expand = 1)
textbox = Text(textFrame, font='Arial 14', wrap='word')
scrollbar = Scrollbar(textFrame)
scrollbar['command'] = textbox.yview
textbox['yscrollcommand'] = scrollbar.set
textbox.pack(side = 'left', fill = 'both', expand = 1)
scrollbar.pack(side = 'right', fill = 'y')
loadBtn = Button(panelFrame, text = 'Load')
saveBtn = Button(panelFrame, text = 'Save')
quitBtn = Button(panelFrame, text = 'Quit')
button_done = Button(panelFrame, text='Do me!')
loadBtn.bind("", LoadFile)
saveBtn.bind("", SaveFile)
quitBtn.bind("", Quit)
button_done.bind("", but_clicked)
loadBtn.place(x = 10, y = 10, width = 40, height = 40)
saveBtn.place(x = 60, y = 10, width = 40, height = 40)
quitBtn.place(x = 170, y = 10, width = 40, height = 40)
button_done.place(x = 110, y = 10, width = 50, height = 40)
root.mainloop()
__author__ = 'nibbler'