横向的选项卡标签和动态生成标签
import tkinter as tk
from tkinter import ttk
import os
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
self.__win()
self.file_system_watcher = FileWatcher("D:/Python/Reporting")
self.style = ttk.Style()
self.style.configure("lefttab.TNotebook", tabposition="wn")
self.notebook = ttk.Notebook(self, style="lefttab.TNotebook")
if self.file_system_watcher.fileExists("mian.py"):
ec_tab = ttk.Frame(self.notebook)
self.notebook.add(ec_tab, text="main")
button1 = ttk.Button(ec_tab, text="按钮1")
button1.pack()
if self.file_system_watcher.fileExists("test.py"):
test_tab = ttk.Frame(self.notebook)
self.notebook.add(test_tab, text="test")
button1 = ttk.Button(test_tab, text="按钮2")
button1.pack()
if self.file_system_watcher.fileExists("setup.py"):
test_tab = ttk.Frame(self.notebook)
self.notebook.add(test_tab, text="setup")
button1 = ttk.Button(test_tab, text="按钮3")
button1.pack()
self.notebook.pack()
def __win(self):
self.title("EXE")
width = 710
height = 565
screenwidth = self.winfo_screenwidth()
screenheight = self.winfo_screenheight()
geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
self.geometry(geometry)
self.minsize(width=width, height=height)
class FileWatcher:
def __init__(self, path):
self.path = path
def fileExists(self, file_name):
return os.path.exists(os.path.join(self.path, file_name))
if __name__ == "__main__":
window = MainWindow()
window.mainloop()