Gui在Python 3.3中?

时间:2014-06-03 11:09:09

标签: python python-3.3

我想以GUI的形式为我的程序创建一个菜单,用户可以通过单击一个框而不是键入数字/字母来选择他们想要的内容。这是我到目前为止所得到的:

while True:
    encrypt = False
    decrypt = False
    viewz = False
    errorz = False
    inp = input("Do you want to [E]ncode, [D]ecode, [V]iew Code or [EX]it:")
    inp = inp.lower()
    if (inp != "e"  and inp != "d" and inp != "encode" and inp != "decode" and inp != "v" and inp != "view code" ):
        print("Input error")
        print()
        continue
    if inp == "e" or inp == "encode":
        encrypt = True
    if inp == "d" or inp == "decode":
        decrypt = True

1 个答案:

答案 0 :(得分:1)

这是Windows上的python 3.3的tkinter示例。不完全确定你在哪里,但希望它有所帮助。

import tkinter as tk

window = tk.Tk()

encrypt = False
decrypt = False
viewz = False
errorz = False # Not sure why you had this, but included it as it may be handy for you

def encode():
    encrypt = True
    window.destroy()

def decode():
    decrypt =True
    window.destroy()

def viewcode():
    viewz = True # I think this is what you were going to do here?
    window.destroy()

def Exit():
    window.destroy() # Assuming you want the exit button to exit the tk window

label = tk.Label(text = "Do you want to:")
encodebutton = tk.Button(text = "Encode", command = encode)
decodebutton = tk.Button(text = "Decode", command = decode)
viewcodebutton = tk.Button(text = "View Code", command = viewcode)
exitbutton = tk.Button(text = "Exit", command = Exit)
# Theres heaps more you can do with tkinter, google it and give it a go it's heaps of   fun.
label.pack()
encodebutton.pack()
decodebutton.pack()
viewcodebutton.pack()
exitbutton.pack()

window.mainloop()
# After this you go on with your code :p