【问题标题】:(Python 2.7) easygui.choicebox if else statement how to [closed](Python 2.7)easygui.choicebox if else 语句如何[关闭]
【发布时间】:2013-10-08 21:59:28
【问题描述】:

我正在尝试在 python 中为我的 mac 制作一个 mac 地址欺骗器,因为我发现其他软件是不必要的高级/难以理解。首先,我想要一个选择框,询问您要欺骗什么设备,但我无法让 if else 语句起作用。如果 coice 是第一个则输入该值 elif 选择是第二个输入该值。如果以上都不是,你做错了什么。我正在运行 python 2.7

TlDr;如果 Else 语句不能按我的意愿工作(python 2.7)。

代码如下:

#_._# Mac Changer #_._#
import easygui


msg = "What Device do you want to spoof you're mac addresse?"
title = "SpoofMyMac"
choices = ["en0 (Ethernet)", "en1 (WiFi)"]
choice = easygui.choicebox(msg, title, choices)

#####################################
if choice == choice[0]:             #
    easygui.msgbox("Ethernet")      #
elif choice == choice[1]:           # This is where the problem seems to be.
    easygui.msgbox("Wifi")          #
else:                               #
    easygui.msgbox("chus somthin!") #
#####################################

现在这只是代码的开始,有人愿意帮我解决这个 if else 语句吗?

提前谢谢! :)

【问题讨论】:

    标签: python macos python-2.7 if-statement easygui


    【解决方案1】:

    据我所知,您只是有一个错字。你想索引choices,而不是choice

    if choice == choices[0]:  
        #index choices ^           
        easygui.msgbox("Ethernet")      
    elif choice == choices[1]:
        #index choices ^          
        easygui.msgbox("Wifi")          
    else:                               
        easygui.msgbox("chus somthin!")
    

    【讨论】:

    • 非常感谢! :) 我的愚蠢错误。 :P
    猜你喜欢
    • 2017-09-05
    • 2016-10-15
    • 2018-03-29
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多