I am continuing that cryptographical program, and now I'm developing GUI for it. I have weird problem, though: in main menu i have buttons calling out encrypting and decrypting subprograms, but they are apparently being executed BEFORE button is pressed.
definitions.py
#!/usr/bin/env python2.7
#-*- encoding: utf-8 -*
from Tkinter import *
import decoding
import encoding
version="v0.0"
def NewLabel(text, column, row, self):
label=Label(self, text=text)
label.grid(column=column,row=row)
def NewButton(text, action, column, row, self, sticky="N"):
button=Button(self, text=text, command=action)
button.grid(column=column,row=row,sticky=sticky)
def OnEncode():
zxc.encode() #zxc is the new encode
quit()
def OnDecode():
decoding.decode(version)
def OnExit():
quit()
welcome.py
#!/usr/bin/env python2.7
#-*- encoding: utf-8 -*
from Tkinter import *
from definitions import *
import encoding
import decoding
import zxc
main_window=Tk()
mainContainer=Frame(main_window)
NewLabel(u'Welcome to <name> GUI alpha v0.0',0,0,mainContainer)
NewLabel(u'What do you want to do?',0,1,mainContainer)
NewButton(u'1. Encrypt file',OnEncode,0,2,mainContainer)
NewButton(u'2. Decrypt file',OnDecode,0,3,mainContainer)
NewButton(u'Exit',OnExit,0,4,mainContainer)
mainContainer.pack()
main_window.title('<name> GUI')
main_window.mainloop()
zxc.py
#!/usr/bin/env python2.7
#-*- encoding: utf-8 -*
from definitions import *
class encode(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent=parent
self.initialize()
def harden(number):
if number<=80: number=53
elif number>=100: number=((1/2)*number+50)
elif 82<number<100: number=((number**2-4)*(number**2-1))/number
return number
def initialize(self):
NewLabel('Welcome to <name> GUI v0.0 encoder',0,0,self)
app=encode(None)
app.title('<name> GUI v0.0 encoder')
app.mainloop()
What i get from this is first "Welcome to GUI v0.0 encoder" window, and after i close that "welcome to GUI alpha v0.0" with buttons appears