简体   繁体   中英

How to run a python file with the click of a button in tkinter?

I am making a menu screen for a game and want to open the main game screen using a python file when you click the button.

This is the button code:

Play = Button(root, text="PLay(Bot)", fg="blue", bg="cyan", command=open)

and the game file path is (C:\Users\PCCF(HOFF)\PycharmProjects\RPS pythonGUI\GAME.py)

Try this

import subprocess
Play = Button(t, text="PLay(Bot)", fg="blue", bg="cyan", 
              command=lambda:subprocess.Popen(args=['python', r'C:\Users\PCCF(HOFF)\PycharmProjects\RPS pythonGUI\GAME.py'])))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM