LoginSignup
1
1

More than 5 years have passed since last update.

ダイアログのユーザ入力で処理を変える

Posted at

ダイアログを表示してユーザが選んだ入力に応じて処理を変えてみる。

dialog.py
# -*- coding: utf-8 -*-

import tkinter.messagebox as mb
import webbrowser

# chromeで開きたい場合
b = webbrowser.get('"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %s')

if __name__ == '__main__':
    # ユーザの入力に応じて処理を変える
    if mb.askyesno("Title", "Open chrome browser?"):
        b.open("http://www.yahoo.co.jp")
    else:
        print("do nothing")

簡単にできますね!
ダイアログはTkinterというPythonでGUIを組むことのできるツールキットを利用してます。

こちらの記事を参考に。
PythonのTkinterを使ってみる

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1