As the title suggests, there are some major flaws in my new program, though it still functions nonetheless. Here's the code:
POS = 1
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
import os
def clear():
if os.name == "nt":
os.system("cls")
else:
print ("\n"*40)
def key(event):
clear()
global POS
global MENU
MENU = "Nothing selected"
if event.keysym == 'Escape':
root.destroy()
if (event.keysym in ["Up", "Down"]) == True:
direction = event.keysym
if direction == "Down":
if POS == 9:
POS = 1
else:
POS += 1
if direction == "Up":
if POS == 1:
POS = 9
else:
POS -= 1
if (event.keysym) == "Return":
MENU = str(POS)
if POS == 1:
POS1 = "->"
else:
POS1 = " "
if POS == 2:
POS2 = "->"
else:
POS2 = " "
if POS == 3:
POS3 = "->"
else:
POS3 = " "
if POS == 4:
POS4 = "->"
else:
POS4 = " "
if POS == 5:
POS5 = "->"
else:
POS5 = " "
if POS == 6:
POS6 = "->"
else:
POS6 = " "
if POS == 7:
POS7 = "->"
else:
POS7 = " "
if POS == 8:
POS8 = "->"
else:
POS8 = " "
if POS == 9:
POS9 = "->"
else:
POS9 = " "
if POS == 1:
POS1 = "->"
else:
POS1 = " "
print (" Press escape to quit")
print ("---------------------")
print (POS1, "1) Position 1")
print (POS2, "2) Position 2")
print (POS3, "3) Position 3")
print (POS4, "4) Position 4")
print (POS5, "5) Position 5")
print (POS6, "6) Position 6")
print (POS7, "7) Position 7")
print (POS8, "8) Position 8")
print (POS9, "9) Position 9")
print ("---------------------")
print (MENU)
print ("Welcome to InterfaceTest v0.1 alpha")
print ("Hit any key to begin")
root = tk.Tk()
root.bind_all('<Key>', key)
root.withdraw()
root.mainloop()
You first of all probably noticed that you can't click any where with the mouse other wise it doesn't work. This isn't really debug friendly either, because it isn't compatible with most IDE's. You also see the part where you have lots of repetitive code. Would've used a for loop but I can't seem to figure out how to combine the loop variable and the normal variable.
SO.....
Other than that it's all working hunky dory, not really... I need to find out some way to fix the clicking thing, and optimize that big block of repetitive code in the middle of the script. I've tried everything and nothing seems to work.