纳西妲牌羽毛球 2022-07-06 21:18 采纳率: 75%
浏览 30
已结题

制作tkinter界面时发现点击按钮无法出现TopLevel

我在做管理系统时出现了问题,编辑器是pycharm,界面是tkinter,刚刚做了一半就有了问题😅(部分代码来自普通网友)

img

import tkinter
from socket import *
from tkinter import ttk
from tkinter import messagebox

name = ''


def hello_screen():
    hello = tkinter.Tk()
    hello.title('实验室管理系统')
    hello.geometry('417x500')
    img1 = tkinter.PhotoImage(file="C://Users//a//Desktop//R-C(1).png")
    img2 = tkinter.PhotoImage(file="C://Users//a//Desktop//bbd_Convert.gif")
    laaa = tkinter.Label(hello, image=img2)
    laaa.place(x=1, y=0)
    label1 = tkinter.Label(hello, image=img1)
    label1.place(x=1, y=0)
    label2 = tkinter.Label(hello, text='用户名')
    label2.place(y=270, x=30)
    input1 = tkinter.Entry(hello, width=35, textvariable=name)
    input1.place(x=75, y=275, height=20)
    xVariable = tkinter.StringVar()
    com = ttk.Combobox(hello, textvariable=xVariable)  # #创建下拉菜单
    com.pack()  # #将下拉菜单绑定到窗体
    com["value"] = ("课题组长", "导师", "学生")  # #给下拉菜单设定值
    com.current(0)
    com.place(x=75, y=310)
    law = tkinter.Label(hello, text='身份')
    law.place(x=30, y=310)
    img3 = tkinter.PhotoImage(file="C://Users//a//Desktop//R-C1(1).png")
    button = tkinter.Button(hello, image=img3, relief='flat')
    button.place(x=250, y=400)
    name1 = "欢迎使用!" + name

    def qui_t():
        hello.destroy()

    def qwe():
        def add_vacc_info(self):
            add_vacc_info = tkinter.Toplevel(hello)
            add_vacc_info.title('添加疫苗信息')
            add_vacc_info.geometry("600x400")
            tkinter.Label(add_vacc_info, text='   学生姓名:', font=("Arial", 9)).place(x=80, y=60)
            tkinter.Label(add_vacc_info, text='   学生年龄:', font=('Arial', 9)).place(x=80, y=90)
            tkinter.Label(add_vacc_info, text='   学生性别:', font=('Arial', 9)).place(x=80, y=120)
            tkinter.Label(add_vacc_info, text='   学生编号:', font=('Arial', 9)).place(x=80, y=150)
            tkinter.Label(add_vacc_info, text='   学生成绩:', font=('Arial', 9)).place(x=80, y=180)
            tkinter.Label(add_vacc_info, text='   学生宿舍:', font=('Arial', 9)).place(x=80, y=210)
            tkinter.Label(add_vacc_info, text='   学生座位:', font=('Arial', 9)).place(x=80, y=240)
            tkinter.Label(add_vacc_info, text='   学生民族:', font=('Arial', 9)).place(x=80, y=270)
            tkinter.Label(add_vacc_info, text='学生政治面貌:', font=('Arial', 9)).place(x=80, y=300)
            entry1 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry2 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry3 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry4 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry5 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry6 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry7 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry8 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry9 = tkinter.Entry(add_vacc_info, font="Arial, 9", width=46)
            entry1.pack()
            entry2.pack()
            entry3.pack()
            entry4.pack()
            entry5.pack()
            entry6.pack()
            entry7.pack()
            entry8.pack()
            entry9.pack()
            entry1.place(x=180, y=60, width=350)
            entry2.place(x=180, y=90, width=350)
            entry3.place(x=180, y=120, width=350)
            entry4.place(x=180, y=150, width=350)
            entry5.place(x=180, y=180, width=350)
            entry6.place(x=180, y=210, width=350)
            entry7.place(x=180, y=240, width=350)
            entry8.place(x=180, y=270, width=350)
            entry9.place(x=180, y=300, width=350)

            def add():
                text1 = entry1.get()
                text2 = entry2.get()
                text3 = entry3.get()
                text4 = entry4.get()
                text5 = entry5.get()
                text6 = entry6.get()
                text7 = entry7.get()
                text8 = entry8.get()
                text9 = entry9.get()
                content = "INSERT INTO vaccine_info (" \
                          "vaccine_num, vaccine_name, company_name, company_num, size, buy_price, pre_sale_price, " \
                          "limit_up, limit_down" \
                          ")" \
                          " VALUES (%s, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');" % (
                              text1, text2, text3, text4, text5, text6, text7, text8, text9)
                self.connect_DBS(database="vaccine_info", content=content)
                tkinter.messagebox.showinfo(title="信息", message="数据添加成功!")

            def clear():
                entry1.delete(0, "end")
                entry2.delete(0, "end")
                entry3.delete(0, "end")
                entry4.delete(0, "end")
                entry5.delete(0, "end")
                tkinter.messagebox.showinfo(title="信息", message="数据已清空,请继续添加!")

            tkinter.Button(add_vacc_info, text="添加", bg='white', font=("Arial,9"), width=9, height=0,
                           command=add).place(
                x=400, y=360)
            tkinter.Button(add_vacc_info, text="清空", bg='white', font=("Arial,9"), width=9, height=0,
                           command=clear).place(
                x=160, y=360)

        def add_vaccine_distr_info():
            add_vaccine_distr_info = tkinter.Toplevel(hello)
            add_vaccine_distr_info.title('添加疫苗分配信息')
            add_vaccine_distr_info.geometry('600x400')
            tkinter.Label(add_vaccine_distr_info, text='疫苗分配单号:', font='Arial, 9').place(x=80, y=60)
            tkinter.Label(add_vaccine_distr_info, text=' 日期:', font='Arial, 9').place(x=80, y=90)
            tkinter.Label(add_vaccine_distr_info, text=' 疫苗批号:', font='Arial, 9').place(x=80, y=120)
            tkinter.Label(add_vaccine_distr_info, text=' 疫苗名称:', font='Arial, 9').place(x=80, y=150)
            tkinter.Label(add_vaccine_distr_info, text=' 企业编号:', font='Arial, 9').place(x=80, y=180)
            tkinter.Label(add_vaccine_distr_info, text=' 质检员编号:', font='Arial, 9').place(x=80, y=210)
            tkinter.Label(add_vaccine_distr_info, text=' 数量:', font='Arial, 9').place(x=80, y=240)
            entry1 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry2 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry3 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry4 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry5 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry6 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry7 = tkinter.Entry(add_vaccine_distr_info, font='Arial, 9', width=46)
            entry1.pack()
            entry2.pack()
            entry3.pack()
            entry4.pack()
            entry5.pack()
            entry6.pack()
            entry7.pack()
            entry1.place(x=180, y=60, width=350)
            entry2.place(x=180, y=90, width=350)
            entry3.place(x=180, y=120, width=350)
            entry4.place(x=180, y=150, width=350)
            entry5.place(x=180, y=180, width=350)
            entry6.place(x=180, y=210, width=350)
            entry7.place(x=180, y=240, width=350)

        def options():
            options = tkinter.Toplevel(hello)
            options.title('功能选项')
            options.geometry("600x500")
            tkinter.Label(options, text='sjkc', font=("KaiTi", 40)).place(x=180, y=15)
            tkinter.Button(options, text='新建学生信息', bg='white', font="Arial,12", width=20, height=2,
                           command=add_vacc_info).place(x=100, y=100)
            tkinter.Button(options, text='新建学生作业', bg='white', font="Arial,12", width=20, height=2,
                           command=add_vaccine_distr_info).place(x=100, y=160)
            # tkinter.Button(options, text='新建疫苗养护信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=add_vaccine_maintenance_info).place(x=100, y=220)
            # tkinter.Button(options, text='新建接种人员信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=add_vaccination_person_info).place(x=100, y=280)
            # tkinter.Button(options, text='查询学生作业信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=vaccine_distr_info_query).place(x=100, y=340)
            # tkinter.Button(options, text='查询学生住宿信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=vaccination_maintenance_info_query).place(x=320, y=100)
            # tkinter.Button(options, text='查询核酸检测信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=vaccination_person_info_query).place(x=320, y=160)
            # tkinter.Button(options, text='查询接种疫苗信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=vaccine_info_query).place(x=320, y=220)
            # tkinter.Button(options, text='修改学生信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=modify_vaccine_info).place(x=320, y=280)
            # tkinter.Button(options, text='删除学生信息', bg='white', font="Arial,12", width=20, height=2,
            #                command=del_vaccine_info).place(x=320, y=340)

        def run():
            options()

        run()

    imp2 = tkinter.PhotoImage(file="C://Users//a//Desktop//9071.png_860(1)(1).png")
    img4 = tkinter.Button(hello, image=imp2, relief='flat', command=lambda: qui_t())
    img4.place(x=100, y=403)
    hello.mainloop()


hello_screen()


运行之后……(本来我想放个录屏,结果发现录不上tkinter窗口……)

反正就是点登录按钮没有任何反应,也不报错,不知道为什么😫

我想要让这个按钮一点击就出现一个窗口,有谁帮帮我啊
  • 写回答

1条回答 默认 最新

  • Kappuccinno 2022-07-06 21:36
    关注

    问题是你这个qwe在主函数里面没用上啊,只是将destroy的绑在了img4上,但你没有和新窗口绑定在一起

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 7月15日
  • 已采纳回答 7月7日
  • 创建了问题 7月6日

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口