Print Text 'Loading' with dots going forward and backward in python shell

后端 未结 4 1059
深忆病人
深忆病人 2021-01-13 07:01

I want to print Text \'Loading...\' But its dots would be moving back and forward (in shell).

I am creating a text game and for that it will look b

4条回答
  •  庸人自扰
    2021-01-13 07:29

    Check This Module Keyboard with many features. Install It, perhaps with this command:

    pip3 install keyboard
    

    Then Write the following code in File textdot.py:

    def text(text_to_print,num_of_dots,num_of_loops):
        from time import sleep
        import keyboard
        import sys
        shell = sys.stdout.shell
        shell.write(text_to_print,'stdout')
        dotes = int(num_of_dots) * '.'
        for last in range(0,num_of_loops):
            for dot in dotes:
                keyboard.write('.')
                sleep(0.1)
            for dot in dotes:
                keyboard.write('\x08')
                sleep(0.1)
    

    Now Paste the file in Lib from your python folder.
    Now you Can use it like following example:

    import textdot
    textdot.text('Loading',6,3)
    

    Thanks

提交回复
热议问题