首页 > 解决方案 > 在 tkinter 中重新启动具有两个窗口框架的程序的功能

问题描述

我在运行此功能时遇到的问题是,每当我重新启动程序时,如果我单击任何按钮,程序就会完全关闭。我不知道这可能是什么原因。该程序有两个窗口,当按下按钮时会打开。我已经在其他程序上尝试了重启 program1 功能,只有一个窗口框架,它运行良好。我不知道这个有什么问题

from tkinter import *
from tkinter import ttk
import tkinter as tk
import os
import sys
class moreTab(tk.Tk):
    def __init__(self ):
        Tk.__init__(self )
        self.geometry("1350x800")
        container = Frame(self, bg='#c9e3c1')
        container.pack(side="top", fill='both', expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self.frames = {}
        for q in (pageone, widget):
            frame = q(container, self)
            self.frames[q] = frame
            frame.grid(row=0, column=0, sticky="nsew")
        self.raise_frame(pageone)
    def raise_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()
class widget(Frame):
    def __init__(self, master=0, control=0):
        Frame.__init__(self, master, bg='#c9e3c1')
        self.amount_played = Label(self, text='Amount',
                font=('Lucida Calligraphy', '15', 'bold'), bd=5, bg='#c9e3c1')
        self.amount_played.place(x=710, y=5)
        self.m = 0
        n = 2
        self.entrybox = Entry(self, width=10)
        self.entrybox.place(x=10, y=90)
        self.entrybox2 = Entry(self, width=10)
        self.entrybox2.place(x=100, y=90)
        self.vs = Label(self, text='vs',
                font=('Lucida Calligraphy', '15', 'bold'), bd=5, bg='#c9e3c1')
        self.vs.place(x=60, y=85)
        self.b = ttk.Button(self, text='print',
                            width=15, command=self.moving_But1)
        self.b.place(x=10, y=120)
        self.b1 = ttk.Button(self, text='start page', width=15,
             command=lambda: control.raise_frame(pageone)).place(x=1200, y=640)
        self.b6 = ttk.Button(self, text='Reset',
                             width=7, command=self.restart_program1)
        self.b6.place(x=660, y=15)
        self.ss = 300
    def moving_But1(self):
        self.ss += 50
        Label(self, text ="i dont think I'm gonna close :)",
              font=('Bradley Hand ITC', '30', 'bold'),
              bg='#c9e3c1').place(x =50, y = self.ss)

        print("i dont think I'm gonna close :)")
    def restart_program1(self):
        os.execl(sys.executable, sys.executable, *sys.argv)
class pageone(Frame):
    def __init__(self, master, control):
        Frame.__init__(self, master, bg='#c9e3c1')
        lab = Label(self, text='welcome to Game Analysis',
                    font=('Bradley Hand ITC', '40', 'bold'), bg='#c9e3c1')
        lab.place(x=10, y=10)
        but = ttk.Button(self, text='start', 
                         width = 15, command=lambda: control.raise_frame(widget))
        but.place(x=1150, y=580)
app = moreTab()
app.mainloop()

标签: pythontkinter

解决方案


推荐阅读