tkinker(2)

#脚本工具代码重构
import openpyxl
from tkinter import filedialog
from tkinter import messagebox
import threading
import re
import tkinter as tk
'''松耦合'''
# 弹窗
class MyDialog(tk.Toplevel):
  def __init__(self):
    super().__init__()
    self.title('文件导入窗口')
    # 弹窗界面
    self.setup_UI()
    self.wm_attributes('-topmost',1)
  def setup_UI(self):
    # 第一行(两列)
    tk.Button(self, text="退出文件导入窗口", width=30, command=self.ExitWin).pack(side=tk.BOTTOM)
    tk.Button(self, text="Import Controller umts radio Files", width=30, command=self.ParBut).pack(side=tk.BOTTOM)
    tk.Button(self, text="Import Parameters Rule File", width=30, command=self.RulBut).pack(side=tk.BOTTOM)
    tk.Button(self, text="Import Cells List File", width=30, command=self.CelBut).pack(side=tk.BOTTOM)

  def ParBut(self):
    global ParFile
    ParFile = filedialog.askopenfilenames()
    #self.destroy() # 销毁窗口
  def RulBut(self):
    global RulFile
    RulFile = filedialog.askopenfilenames()
    #self.destroy() # 销毁窗口
  def CelBut(self):
    global CelFile
    CelFile = filedialog.askopenfilenames()
    #self.destroy()
  def ExitWin(self):
    self.destroy()
# 主窗
class MyApp(tk.Tk):
  def __init__(self):
    super().__init__()
    #self.pack() # 若继承 tk.Frame ,此句必须有!
    self.title('Script Creater V2.0')
    self.geometry('1200x800')
    self.setupUI()
  def setupUI(self):
    tk.Button(self, text="打开文件导入窗口", command=self.ask_filename).pack(side=tk.LEFT)
  def ask_filename(self):
    inputDialog = MyDialog()
    self.wait_window(inputDialog) # 这一句很重要!!!
    print (CelFile)
    print (RulFile)
    print (ParFile)

if __name__ == '__main__':
  app = MyApp()
  app.mainloop()

你可能感兴趣的:(tkinker(2))