标题:关于tkinter 中界面打开的问题
只看楼主
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
结帖率:40%
 问题点数:0 回复次数:2 
关于tkinter 中界面打开的问题
我用tkinter做了一个系统,在主界面上的工作录入按钮运行时新的窗体打开后,新窗体的部分控件在主窗体中显示,请高手帮我看看,谢谢了。
import tkinter as tk
from tkinter import *
import datetime
from tkinter import ttk
import tkinter.font as tkFont
import luru2


g_font = ("Monaco", 12)




def _font(fname="微软雅黑", size=12, bold=tkFont.NORMAL):
    """设置字体"""
    ft = tkFont.Font(family=fname, size=size, weight=bold)
    return ft


def _ft(size=12, bold=False):
    """极简字体设置函数"""
    if bold:
        return _font(size=size, bold=tkFont.BOLD)
    else:
        return _font(size=size, bold=tkFont.NORMAL)


def h_seperator(parent, height=2):  # height 单位为像素值
    """水平分割线, 水平填充 """
    tk.Frame(parent, height=height, bg="whitesmoke").pack(fill=tk.X)


class Win:
    def __init__(self):
        self.root = tk.Tk()
        self.label=Label
        self.root.geometry("%dx%d" % (1200, 800))  # 窗体尺寸
        # center_window(self.root)                   # 将窗体移动到屏幕中央
        self.root.title("党支部管理系统")  # 窗体标题
        # self.root.iconbitmap("images\\Money.ico")  # 窗体图标
        self.root.grab_set()  # 获取部件设置
        self.body()
        self.separator = ttk.Separator(self.root).pack(fill="x")
        self.status = ttk.Frame(self.root, relief="raised").pack(fill="x")
        self.lable = ttk.Label(self.root, text="当前登录用户:" + "++++" + " | 登录时间:" + datetime.datetime.now().strftime(
            "%Y-%m-%d %H-%M-%S") + " | 制作:王建校").pack()

    def body(self):
        self.title(self.root).pack(fill=tk.X)
        self.main(self.root)

    def title(self,parent):
        """ 标题栏 """
        def label(frame, text, size, bold=False):
            return tk.Label(frame, text=text, bg="black", fg="white", height=2, font=_ft(size, bold))
        frame = tk.Frame(parent, bg="black")
        label(frame, "支部管理应用平台", 16, True).pack(side=tk.LEFT, padx=10)
        Button(frame, text="操作指南", font=12, bg="black", fg="white", relief=FLAT).pack(side=tk.LEFT, padx=100)

        Button(frame, text="支部制度", font=12, bg="black", fg="white", relief=FLAT).pack(side=tk.LEFT, padx=0)
        Button(frame, text="工作录入", font=12, bg="black", fg="white", relief=FLAT,command=luru2.Luru).pack(side=tk.LEFT, padx=100)
      
        return frame

    def main(self,parent):
        self.frm = tk.Frame(parent, bg="whitesmoke")
        self.frm.pack(fill="both", expand=1)

        self.frm_choose = tk.LabelFrame(self.frm,width=200)
        self.frm_choose.pack(fill="y", padx=1, side=tk.LEFT)

        self.frm_show = tk.LabelFrame(self.frm,width=950)
        self.frm_show.pack(fill="both", expand=1, padx=4, side=tk.RIGHT)

        self.create_frm_choose()
        self.create_frm_show()

    def create_frm_choose(self):
        '''
        create frame choose
        '''
        def label(frm_choose, text, size=10, bold=False):
            return tk.Label(frm_choose, text=text, font=_ft(size, bold))
        label(self.frm_choose, "支部资料目录", 16, True).pack(anchor=tk.W, padx=20, pady=40)
        self.choose_info_lst = ["党员管理", "三会一课", "特色工作", "谈心谈话","党风廉洁","计划总结"]
        self.choose_btn_lst = list()
        for index, value in enumerate(self.choose_info_lst):
            temp_btn = tk.Button(self.frm_choose,
                                 anchor="w",
                                 text=value,
                                 font=12,
                                 relief=FLAT,
                                 state="normal",
                                 activeforeground="red")
            temp_btn.bind('<Button-1>', self.btn_click)
            temp_btn.pack( padx=2, pady=6,side=tk.TOP)
            self.choose_btn_lst.append(temp_btn)

    def create_frm_show(self):
        '''
        create frame show
        '''

        self.show_note0= ttk.Notebook(self.frm_show)
        pane1=Frame()
        pane2=Frame()
        pane3 = Frame()
        self.show_note0.add(pane1,text="党员信息")
        self.show_note0.add(pane2, text="入党积极分子管理")
        self.show_note0.add(pane3, text="党员评议")
        self.show_note0.pack_forget()

        self.show_note1 = ttk.Notebook(self.frm_show)
        pane1 = Frame()
        pane2 = Frame()
        pane3 = Frame()
        pane4 = Frame()
        pane5 = Frame()
        self.show_note1.add(pane1, text="支委会")
        self.show_note1.add(pane2, text="党小组会")
        self.show_note1.add(pane3, text="党课学习")
        self.show_note1.add(pane4, text="党员大会")
        self.show_note1.add(pane5, text="组织生活会")
        self.show_note1.pack_forget()

        self.show_note2 = ttk.Notebook(self.frm_show)
        pane1 = Frame()
        pane2 = Frame()
        pane3 = Frame()
        pane4 = Frame()
        self.show_note2.add(pane1, text="主题党日")
        self.show_note2.add(pane2, text="主题教育")
        self.show_note2.add(pane3, text="特色活动")
        self.show_note2.add(pane4, text="志愿者活动")
        self.show_note2.pack_forget()

        self.show_note4 = ttk.Notebook(self.frm_show)
        pane1 = Frame()
        pane2 = Frame()
        pane3 = Frame()
        self.show_note4.add(pane1, text="廉洁教育记录")
        self.show_note4.add(pane2, text="信访记录")
        self.show_note4.add(pane3, text="廉洁责任区管理")
        self.show_note4.pack_forget()

        self.show_note3 = ttk.Notebook(self.frm_show)
        pane1 = Frame()
        pane2 = Frame()
        pane3 = Frame()

        self.show_note3.add(pane1, text="沟通谈话")
        self.show_note3.add(pane2, text="廉洁谈话")
        self.show_note3.add(pane3, text="征求意见谈话")
        self.show_note3.pack_forget()

        self.show_note5 = ttk.Notebook(self.frm_show)
        pane1 = Frame()
        pane2 = Frame()
        self.show_note5.add(pane1, text="工作计划")
        self.show_note5.add(pane2, text="工作总结")
        self.show_note5.pack_forget()



    def btn_click(self, event=None):
        '''
        choose frm
        '''

        def label(frm_show, text, size=10, bold=False):

            return tk.Label(frm_show, text=text, font=_ft(size, bold))

        btn_text = event.widget['text']


        label(self.frm_show,btn_text, 16, True).configure(anchor=tk.W, padx=20, pady=20)

        

        if btn_text == "党员管理":
            self.show_note0.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
            self.show_note1.pack_forget()
            self.show_note2.pack_forget()
            self.show_note3.pack_forget()
            self.show_note4.pack_forget()
            self.show_note5.pack_forget()

        elif btn_text == "三会一课":
            self.show_note0.pack_forget()
            self.show_note2.pack_forget()
            self.show_note3.pack_forget()
            self.show_note4.pack_forget()
            self.show_note5.pack_forget()
            self.show_note1.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
        elif btn_text == "特色工作":
            self.show_note0.pack_forget()
            self.show_note1.pack_forget()
            self.show_note3.pack_forget()
            self.show_note4.pack_forget()
            self.show_note5.pack_forget()
            self.show_note2.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
        elif btn_text == "谈心谈话":
            self.show_note0.pack_forget()
            self.show_note1.pack_forget()
            self.show_note2.pack_forget()
            self.show_note4.pack_forget()
            self.show_note5.pack_forget()
            self.show_note3.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
        elif btn_text == "党风廉洁":
            self.show_note0.pack_forget()
            self.show_note1.pack_forget()
            self.show_note2.pack_forget()
            self.show_note3.pack_forget()
            self.show_note5.pack_forget()
            self.show_note4.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
        elif btn_text == "计划总结":
            self.show_note0.pack_forget()
            self.show_note1.pack_forget()
            self.show_note2.pack_forget()
            self.show_note3.pack_forget()
            self.show_note4.pack_forget()
            self.show_note5.pack(fill="both", expand=1, padx=2, pady=2,side=tk.TOP)
if __name__ == '__main__':
    app=Win()
    app.root.mainloop()

新窗体
import tkinter as tk
from tkinter import *
import datetime
from tkinter import ttk
import tkinter.font as tkFont


class Luru:
    def __init__(self):
        self.win = tk.Tk()
        self.win.geometry("%dx%d" % (800, 600))
        self.win.title("支部工作录入")
        Label(self.win, text="党支部工作情况录入", font=16, bg="royalblue", fg="white", height=2).pack(side=tk.TOP, fill="x")
        self.frm_1 = tk.Frame(self.win, bg="whitesmoke").pack(fill="both", expand=1, side=tk.TOP)
        self.frm_main1 = ttk.Notebook(self.frm_1, height=500)
        pane_1 = Frame()
        pane_2 = Frame()
        pane_3 = Frame()
        pane_4 = Frame()
        pane_5 = Frame()
        pane_6 = Frame()
        self.frm_main1.add(pane_1, text="党员管理")
        self.frm_main1.add(pane_2, text="三会一课")
        self.frm_main1.add(pane_3, text="特色工作")
        self.frm_main1.add(pane_4, text="谈心谈话")
        self.frm_main1.add(pane_5, text="党风廉洁")
        self.frm_main1.add(pane_6, text="计划总结")
        self.frm_main1.pack(fill="both", expand=1, padx=2, pady=2, side=tk.TOP)
        status = ttk.Frame(self.win, relief="raised")
        status.pack(fill="x")
        Label(self.win, text="当前登录用户:" + "++++" + " | 登录时间:" + datetime.datetime.now().strftime(
            "%Y-%m-%d %H-%M-%S") + " | 制作:王建校").pack()
        self.win.mainloop()
搜索更多相关主题的帖子: size add Frame label text 
2022-05-18 15:44
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
得分:0 
问题已解决
2022-05-25 10:24
sssooosss
Rank: 9Rank: 9Rank: 9
等 级:禁止访问
威 望:3
帖 子:664
专家分:1115
注 册:2019-8-27
得分:0 
共同学习
2022-05-25 16:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-509113-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.217831 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved