如何关闭python但保持执行运行

2024-05-14 02:48:28 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有两个按钮可以调用快捷方式,但是我需要关闭python运行,但是被调用的程序保持运行。因为每次我按下按钮,python都会关闭,进程永远不会继续

有什么想法吗

谢谢

import os
import tkinter as tk
from tkinter import *

def vulkan():
    os.startfile (r"F:\\Games\\RetroArch\\retroarch_vulkan.lnk")
    root.quit()

def default():
    os.startfile (r"F:\\Games\\RetroArch\\retroarch_gl.lnk")
    root.quit()

HEIGHT = 600
WIDTH = 800

root = tk.Tk()
root.title("Pick your choise")

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

x_coordinate = (screen_width/2) - (WIDTH/2)
y_coordinate = (screen_height/2) - (HEIGHT/2)

root.geometry ("%dx%d+%d+%d" % (WIDTH, HEIGHT, x_coordinate, y_coordinate))

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

#frame = tk.Frame(root, highlightbackground='black', highlightthickness=1, bd=10)
frame = tk.Frame(root, bd=10)
frame.place(relx = 0.5, rely=0.5, relwidth=0.95, relheight=0.95, anchor="c")

button = tk.Button(frame, text="RetroArch Vulkan", font=60, command=lambda: vulkan())
button.place(relx = 0.05, relwidth=0.4, relheight=1)

button2 = tk.Button(frame, text="RetroArch glcore", font=60, command=lambda: default())
button2.place(relx = 0.55, relwidth=0.4, relheight=1)

root.mainloop()

Tags: importcoordinateosplacerootwidthscreenframe
1条回答
网友
1楼 · 发布于 2024-05-14 02:48:28

使用pip install pyinstaller转换为exe,然后使用pyinstall onefile(yourapp).py 然后运行exe?如果不需要控制台,请安装pynoconsole-onefile(yourapp.py)

相关问题 更多 >