简体   繁体   English

我刚开始 python,我正在尝试制作剪刀石头布游戏,但我不知道如何更改字体及其大小

[英]I've just started python and I'm trying to make a Rock ,Paper ,Scissors game and I can't work out how to change the font and its size

Here is my code if anyone can help then that would be greatly apricated.这是我的代码,如果有人可以提供帮助,那将是非常重要的。

import random

a = ["rock", "paper", "scissors"]

def game():
    while True:
        try:
            word = input('Enter rock, paper, or scissors: ')
            if word not in a:
                raise ValueError # this will send it to the print message and back to the input option
            break 
          
        except ValueError:
            print(" You must enter rock, paper, or scissors.")


    comp_draw = random.choice(a)
    print('The computer drew ' + comp_draw)

    if comp_draw == 'rock' and word =='rock':
        print('It was a tie')
    elif comp_draw == 'paper' and word =='paper':
        print('It was a tie')
    elif comp_draw == 'scissors' and word =='scissors':
        print('It was a tie')
    elif comp_draw == 'paper' and word =='rock':
        print('GAME OVER')
    elif comp_draw == 'rock' and word =='paper':
        print('you won!')
    elif comp_draw == 'rock' and word =='scissors':
        print('GAME OVER')
    elif comp_draw == 'scissors' and word =='rock':
        print('you won!')
    elif comp_draw == 'scissors' and word =='paper':
        print('GAME OVER')
    elif comp_draw == 'scissors' and word =='rock':
        print('you won!')


if __name__ == "__main__":
    game()
    while True:
        if input('Would you like to play_again? ') == 'yes':
            game()
        else:
          break
        
      font = 'Arial (sans-serif)' : 'normal' 
        'weight' : 'bold',
        'size'   : 99} 

This is how I've tried to change the font这就是我尝试更改字体的方式

font = 'Arial (sans-serif)' : 'normal' 
        'weight' : 'bold',
        'size'   : 99} 

This is the error message I've received这是我收到的错误信息

IndentationError: unindent does not match any outer indentation level on line 48 font = 'Arial (sans-serif)': 'normal' ^ in main.py IndentationError: unindent does not match any outer indentation level on line 48 font = 'Arial (sans-serif)': 'normal' ^ 在 main.py

For the code to work, you need to unindent font, add a comma after 'normal' and add an opening brace:为了使代码正常工作,您需要取消缩进字体,在“normal”之后添加一个逗号并添加一个左大括号:

if __name__ == "__main__":
    game()
    while True:
        if input('Would you like to play_again? ') == 'yes':
            game()
        else:
          break
        
font = {'Arial (sans-serif)' : 'normal' ,
       'weight' : 'bold',
       'size'   : 99} 

However, you are not using the font variable so it won't change anything.但是,您没有使用字体变量,因此它不会改变任何内容。 As has been mentioned, if you are printing to the terminal you can't change the font in python.如前所述,如果您要打印到终端,则无法更改 python 中的字体。

Unfortunately, there isn't an easy way for changing the printed font and it's size through Python. You can try changing the console font and size using the shell's api, but this is very platform specific and isn't easy to set up.不幸的是,没有一种简单的方法来更改打印的字体,它的大小一直到 Python。您可以尝试使用 shell 的 api 更改控制台字体和大小,但这是非常特定于平台的,并且不容易设置。

What you can do, is use a simple graphics library like pygame , where you can output graphics from your python application.您可以做的是使用像pygame这样的简单图形库,您可以在其中从 python 应用程序中获取 output 图形。 You can check out this docs to learn how to use fonts in pygame.您可以查看文档以了解如何在 pygame 中使用 fonts。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试在 python 中制作一个石头剪刀布游戏,但我得到一个 unindent 与任何外部缩进杆错误不匹配 - I'm trying to make a rock paper scissors game in python, but am getting an unindent does not match any outer indent lever error 我正在使用 Tkinter 在 Python 中制作剪刀石头布游戏。 我的分数工作不正常 - I'm Making a Rock Paper Scissors game in Python with Tkinter. My Score isn't Working Properly 如何用Python完成此“剪刀石头布”游戏? - How do I finish this Rock, Paper, Scissors game in Python? 如何使我的Rock,Paper和剪刀游戏的代码不那么多余? - How can I make my code for a game of Rock, Paper, and scissors less redundant? 我该怎么办这个石头剪刀布游戏我只是不知道从这里开始? - what do i do with this rock paper scissors game i just don't where to go with it from here? 我正在创建一个类似于石头剪刀布游戏的游戏,但它不起作用 - I am creating a game close to rock paper scissors game but it won't work 如何在石头剪刀布游戏中记分? - How do I keep score in a rock paper scissors game? 如何用更少的代码行制作我的基本的 Rock/Paper/Scissors 游戏? - How do I make my basic Rock/Paper/Scissors game with fewer lines of code? 如何在我的石头剪刀布游戏中再添加一轮 - How can I add another round to my Rock Paper Scissors game 如何在剪刀石头布游戏中实现输赢统计? - How can I Implement Win/loss statistics in Rock Paper Scissors Game?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM