Files
SOMEIP/code_generator/backup/old/tkinter_ui.py

52 lines
2.0 KiB
Python
Raw Normal View History

2026-06-09 20:16:47 +08:00
# coding=utf-8
from doctest import OutputChecker
import sys
import tkinter as tk
from tkinter import scrolledtext, ttk, messagebox
import time
# 获取当前时间
def Time(): #getCurrentTime
current_time = time.strftime('[%Y-%m-%d %H:%M:%S]',time.localtime(time.time()))
return current_time
#设置窗口宽高,以及窗口在屏幕居中显示
def setWindowCenter(root, width, height):
screenwidth = root.winfo_screenwidth() # 获取显示屏宽度
screenheight = root.winfo_screenheight() # 获取显示屏高度
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2) # 设置窗口居中参数
root.geometry(size) # 让窗口居中显示
def instantiate_the_window(window_name):
#实例化一个窗体
window = tk.Tk()
window.title(window_name) #窗口名
#setWindowCenter(window, 800, 400) #窗口居中,传入窗口句柄和窗口宽高
return window
def instantiate_the_note(window):
#在窗体win中创建一个Notebook并承载以下两个选项卡
note = ttk.Notebook(window)
return note
def instantiate_the_tab(note, tab_name):
#在窗体win中创建一个Notebook并承载以下两个选项卡
tab = ttk.Frame(note,relief="solid",borderwidth=1)
note.add(tab, text = tab_name) #选项卡
note.pack()
return tab
def instantiate_the_group(tab, group_name, _row=0, _column=0, _padx=10, _pady=10):
group = tk.LabelFrame(tab, text=group_name) #创建Frame一组
group.grid(row = _row, column = _column, padx = _padx, pady = _pady)
return group
def instantiate_the_element(group,ele_type,ele_name,row,column,padx,pady):
#if ele_type
None
# 打印日志定向到滚动文本框
def direct_log_to_scrolledtext(tab):
log_data_Text = scrolledtext.ScrolledText(tab, width=100, height=10, relief="solid")
log_data_Text.pack()
sys.stdout = OutputChecker.StdoutRedirector(log_data_Text)