Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中创建文本冒险UI的最佳方法_Python_User Interface_Text - Fatal编程技术网

在Python中创建文本冒险UI的最佳方法

在Python中创建文本冒险UI的最佳方法,python,user-interface,text,Python,User Interface,Text,我对python非常陌生,正在尝试制作一个经典的文本冒险。目前我的基本游戏只是在命令提示符下玩。 我将如何制作一个简单的UI: 在白色背景上以黑色大字体打印游戏文本 底部有一个输入框,用于收集将要输入的输入 解释。(类似于命令提示符) 本质上是与Zork相似的UI。 我试着使用tkinter,但最终我感到困惑,效率低下。另外,如果你想知道的话,我不想只使用命令提示符,因为文本很小,很难阅读 以下是主要的游戏代码,如果有帮助的话: from player import Player #intro

我对python非常陌生,正在尝试制作一个经典的文本冒险。目前我的基本游戏只是在命令提示符下玩。 我将如何制作一个简单的UI:

  • 在白色背景上以黑色大字体打印游戏文本
  • 底部有一个输入框,用于收集将要输入的输入 解释。(类似于命令提示符)
  • 本质上是与Zork相似的UI。 我试着使用tkinter,但最终我感到困惑,效率低下。另外,如果你想知道的话,我不想只使用命令提示符,因为文本很小,很难阅读

    以下是主要的游戏代码,如果有帮助的话:

    from player import Player
    
    #intro screen
    def intro():
        print('Incarnation')
        print('''
        Welcome to Incarnation, please type an option:
        - Play
        - Load
        - Instructions
        - Credits
        - Quit
        ''')
        option = input('>').lower()
        if option == 'play':
            play()
        elif option == 'instructions':
    
            print("""
            Objective: The objective of the game is to complete the narrative by exploring
            the world, collecting items, defeating enemies and solving puzzles.
            You control your character by typing commands.
            Here are some essential commands, make sure to experiment! They are not case sensitive.
            N, S, E, W: Move your character in the cardinal directions
            I: Open your inventory
            H: Heal with an item in your inventory
            A *item*: Attack with an item. Replace *item* with the name of the item.
            T *NPC*: Talk to a present NPC. Repalce *NPC* with the name of the person.
            """)
        elif option == 'credits':
            print('made by Lilian Wang')
        elif option == 'load':
            pass
        elif option == 'quit':
            quit()
        else:
            print("That's not an option.")
    
    player = Player()
    
    # Possible player actions
    def actions(action):
        if action == 'n':
            player.move_north()
        elif action == 's':
            player.move_south()
        elif action == 'e':
            player.move_east()
        elif action == 'w':
            player.move_west()
        elif 'heal' in str(action):
            player.heal(action)
        else:
            print("You can't do that.")
            player.previousLocation = player.location
    
    
    # Main game function
    def play():
        print(player.location.name)
        while player.gameover == False:
            if player.previousLocation != player.location:
                print(player.location.name)
            action = input(">")
            actions(action)
    
    intro()
    

    尝试使用
    PyQt4
    ,这对于开始使用GUI很好,然后您可以轻松地移植到PyQt5。 simpe Hello World计划的一个示例: 导入系统 从PyQt4导入QtGui

    def window():
       app = QtGui.QApplication(sys.argv)
       w = QtGui.QWidget()
       b = QtGui.QLabel(w)
       b.setText("Hello World!")
       w.setGeometry(100,100,200,50)
       b.move(50,20)
       w.setWindowTitle("PyQt")
       w.show()
       sys.exit(app.exec_())
        
    if __name__ == '__main__':
       window() 
    
    输出:

    PyQt4是GUI设计的最佳模块,非常容易学习。我最近用PyQt4实现了一个潜移默化的巅峰:

    您可以开始学习PyQt4


    希望能有帮助。

    Hmmm看起来很有趣,我来看看!每次他们输入命令时,我该如何将新文本打印到屏幕上?我现在无法解释。您可以将按钮创建为选项,因为它可以帮助用户只需单击而不是键入整个选项。首先,您必须学习PyQt4基础知识,然后您可以通过谷歌获得有关基本知识的帮助。:)如果你喜欢,就把答案标对。