Home > Net >  Dialog box in Python
Dialog box in Python

Time:12-18

How to display a dialog box in order to ask the user the number of attempts and the desired language and then pass these values ​​as arguments to a method in Python.

CodePudding user response:

You need to use a GUI Library to show user interface. One such library is Tkinter (already part of Python). You can use the following code:

from tkinter import messagebox

answer = messagebox.askokcancel("Question","Do you want to open this file?")
answer = messagebox.askretrycancel("Question", "Do you want to try that again?")
answer = messagebox.askyesno("Question","Do you like Python?")
answer = messagebox.askyesnocancel("Question", "Continue playing?")

More customization with message box can be found on the following link

CodePudding user response:

Let's say you have a script called "dialog_box.py". Within it, you need to import sys to enable input.

import sys

def desired_language(lang):
    lang = str(lang)
    print(f'Your preferred language is "{lang}".')

if __name__ == '__main__':
    lang = input('Please enter your desired language: ')
    desired_language(lang)

This will ask you for input at the terminal line.

  • Related