在执行python脚本时保持窗口打开



我正在尝试asktoopenfile,获取路径并打开它以制作报告。我的代码如下:

import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
import sys
import os
import openpyxl as xl
import pandas as pd
import numpy as np

def get_file():
global file_abc
file_abc = filedialog.asktoopenfilename(title = "Select A File",filetypes=(("xlsx","*xlsx),("All Files,"*.*)))

window = tk.TK()
window.title("Get File")
window.geometry('1000x1000')

button1 = tk.Button(window,text="File_ABC",command=get_file,bg='#6eb5ff',fg'white',width=100).pack()
button2 = tk.Button(window,text="Run",command=window.destroy,bg='#b28dff',fg'white',width=100).pack()
window.mainloop()
print(file_abc)
abc = pd.read_excel("r'" and file_abc,engine="openpyxl")

但问题是我必须使用window destroy来运行printread_excel脚本。我想问有没有另一种方法可以在执行脚本时保持窗口打开。

感谢并致以最诚挚的问候。

Try This

在其他线程中使用excel命令。这可能有帮助。

import threading
def your_excel_function(word):
print(word)
x = threading.Thread(target=your_excel_function, args=("Hello World"))
x.start()

更好的是,将其作为后台守护进程运行。守护进程是一个后台进程

import threading
def your_excel_function(word):
print(word)
x = threading.Thread(target=your_excel_function, args=("Hello World"), daemon=True)
x.start()

最新更新