# Simple Tkinter GUI for G4AKW Morse Program
# Geoff Robinson Dec 2011
# Version 1.1
from Tkinter import *
'''
This differs from the traditional import statement
in that it puts everything in the module into the
default namespace of this program, so now rather
than needing to refer to a textbox as Tkinter.Textbox
we can just write Textbox
'''
import tkSimpleDialog as tks
import tkMessageBox
root = Tk()
# window geometry is width x height + x_offset + y_offset
root.geometry("600x160+350+300")
root.title('G4AKW Morse Program')
Label(root, text='Enter code to send in box').pack(pady=10)
# Left frame to hold buttons
left = Frame(root)
left.pack(side=LEFT, expand=True, fill=Y)
# Right frame to hold display
right = Frame(root, height=100, width=300, bd=3, relief=GROOVE)
right.pack(expand=True, fill=BOTH)
# change the colour of the right-hand frame
def changeColour(c):
def change():
right.config(background=c)
return change
# Buttons
q_code = ['QSY', 'QRX', 'QRZ?', 'QTH?']
for c in q_code:
b = Button(left, text=c, width=10, command=changeColour(c))
b.pack(side=TOP, expand=True)
def ask():
"""Remember: this Dialog returns a value!"""
morse_speed=str(tks.askinteger("Enter morse speed", " Enter integer value", initialvalue=20))
def station():
station = str(tks.askstring("Distant Station", "enter callsign"))
print station
def your_call():
call = str(tks.askstring("Your Callsign", "enter", initialvalue="G4AKW"))
print call
def your_QTH():
QTH = str(tks.askstring("Your QTH", "enter your location", initialvalue="Woodbridge"))
print QTH
def your_name():
name = str(tks.askstring("Your name", "enter", initialvalue="Geoff"))
print name
def your_rig():
rig = str(tks.askstring("Your Rig", "enter details", initialvalue="FT817 + h/b pa"))
print rig
def your_power():
power = str(tks.askstring("Your Power", "enter output in Watts", initialvalue="400"))
print power
def your_antenna():
antenna = str(tks.askstring("Your Antenna", "enter details", initialvalue="doublet"))
print antenna
def version():
tkMessageBox.showinfo("Version", "1.1")
def send_cq():
cqmsg = "cq cq cq de g4akw g4akw g4akw \
cq cq cq de g4akw g4akw g4akw \
cq cq cq de g4akw g4akw g4akw pse k"
print cqmsg
def end_qso():
end_qso = "mni tnx fer QSO OC \
very best 73 to you and yours \
cul de g4akw + k"
print end_qso
def ok(event):
my_text = e.get()
print my_text
e.delete(0,END)
def hello():
print "hello!"
menubar = Menu(root)
# create the Setup pulldown menu, and add it to the menu bar
setupmenu = Menu(menubar, tearoff=0)
setupmenu.add_command(label="Your Call", command=your_call)
setupmenu.add_command(label="Your QTH", command=your_QTH)
setupmenu.add_command(label="Your name", command=your_name)
setupmenu.add_command(label="Your rig", command=your_rig)
setupmenu.add_command(label="Your power", command=your_power)
setupmenu.add_command(label="Your antenna", command=your_antenna)
setupmenu.add_command(label="What morse speed?", command=ask)
setupmenu.add_separator()
setupmenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Setup", menu=setupmenu)
# create the Call CQ menu button next
menubar.add_command(label="Call CQ", command=send_cq)
# create the Send Station detail pulldown menu
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="5 watts", command=changeColour('green'))
editmenu.add_command(label="100 watts", command=changeColour('yellow'))
editmenu.add_command(label="400 watts", command=changeColour('blue'))
editmenu.add_command(label="1000 watts", command=changeColour('red'))
menubar.add_cascade(label="Send Station Details", menu=editmenu)
# create the End QSO menu button next
menubar.add_command(label="End QSO", command=end_qso)
# last menu button is the help button
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=version)
menubar.add_cascade(label="Help", menu=helpmenu)
# display the menu
root.config(menu=menubar)
# display the RST (Tone) Spinbox
w1 = Spinbox(root, from_=1, to=9, width=2, font=4, wrap=TRUE)
w1.pack(side=RIGHT)
w1.delete(0,"end")
w1.insert(0,9)
# display the RST (Strength) Spinbox
w2 = Spinbox(root, from_=1, to=9, width=2, font=4, wrap=TRUE)
w2.pack(side=RIGHT)
w2.delete(0,"end")
w2.insert(0,9)
# display the RST (Readability) Spinbox
w3 = Spinbox(root, from_=1, to=5, width=2, font=4, wrap=TRUE)
w3.pack(side=RIGHT)
w3.delete(0,"end")
w3.insert(0,5)
# Create Enter Station button
app_button = Button(root, text="Enter Station", width=10, command = station)
app_button.pack(side=LEFT)
# Create Call Station button
app_button = Button(root, text="Call Station", width=10, command = send_cq)
app_button.pack(side=LEFT)
# Create Station report button
app_button = Button(root, text="Station report RST", width=15)
app_button.pack(side=LEFT)
# text entry box
e = Entry(right, width=45)
e.pack(padx=15)
root.bind("
root.mainloop()
Comments