Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 第二个窗口出现在tkinter中_Python_Tkinter - Fatal编程技术网

Python 第二个窗口出现在tkinter中

Python 第二个窗口出现在tkinter中,python,tkinter,Python,Tkinter,然而,当我确保错误部分(仅当圈.dat(包含int列表)出现时,程序才起作用。但是,失败对象的第二个窗口(故意测试错误对象)仍然显示为一个小窗口 from tkinter import * class Error(): def __init__(self): self.root = Tk()#Tk self.root.title("ERROR-PAGE")#name on bar self.root.resizab

然而,当我确保错误部分(仅当
圈.dat
(包含int列表)出现时,程序才起作用。但是,失败对象的第二个窗口(故意测试错误对象)仍然显示为一个小窗口

from tkinter import *
class Error():

    def __init__(self):
            self.root = Tk()#Tk
            self.root.title("ERROR-PAGE")#name on bar
            self.root.resizable(0,0)#doesn't let it be resized

            self.gamefield = Canvas(self.root, width=320, height=480, bg="black") #canvas

            self.top = Frame(self.root)
            self.gamefield.create_text(20, 60, anchor=W, font=("Comic Sans MS", 25),text="We have",fill="white")
            self.gamefield.create_text(20, 100, anchor=W, font=("Comic Sans MS", 25),text="had",fill="white")
            self.gamefield.create_text(20, 140, anchor=W, font=("Comic Sans MS", 25),text="a",fill="white")                        
            self.gamefield.create_text(55, 140, anchor=W, font=("Comic Sans MS", 25,"bold"),text="BAD TIME",fill="cyan")            
            self.gamefield.create_text(20, 180, anchor=W, font=("Comic Sans MS", 25),text="finding 'circles.dat'",fill="white")
            self.gamefield.create_text(20, 220, anchor=W, font=("Comic Sans MS", 25),text="Please place the",fill="white")
            self.gamefield.create_text(20, 260, anchor=W, font=("Comic Sans MS", 25),text="file in the",fill="white")
            self.gamefield.create_text(20, 300, anchor=W, font=("Comic Sans MS", 25),text="same folder as",fill="white")
            self.gamefield.create_text(20, 340, anchor=W, font=("Comic Sans MS", 25),text="the file",fill="white")
            self.gamefield.create_text(20, 390, anchor=W, font=("Comic Sans MS", 25),text="'my_circle.py'",fill="white")
            self.gamefield.pack(side="top")
            self.root.mainloop()



class Mycircle:
    def __init__(self):
        self.root = Tk()#Tk
        self.root.title("My Circle")#name on bar
        self.root.resizable(0,0)#doesn't let it be resized

        self.gamefield = Canvas(self.root, width=640, height=480, bg="white") #canvas

        self.top = Frame(self.root)
        self.count=0#count
        try:            
            with open("circles.dat", "r") as f:
                self.text = [int(a) for l in f for a in l.split()]
        except:
            Error()
        while self.count < len(self.text):
            try:
                self.gamefield.create_oval((self.text[0+self.count]),(self.text[1+self.count]),(self.text[2+self.count]),(self.text[3+self.count]), outline="gray",fill="red", width=2)
                self.count+=4
                self.gamefield.pack(fill=BOTH, expand=1)
            except:
                print("there wasn't enough int to finish another circle")
                self.count+=4
        self.gamefield.pack(side="top")
        self.root.mainloop()#loop



def Main():
    Mycircle()

Main()
从tkinter导入*
类错误():
定义初始化(自):
self.root=Tk()#Tk
self.root.title(“错误页”)#栏上的名称
self.root.resizeable(0,0)#不允许调整大小
self.gamefield=Canvas(self.root,宽度=320,高度=480,bg=“black”)#Canvas
self.top=Frame(self.root)
self.gamefield.create_text(20,60,anchor=W,font=(“Comic Sans MS”,25),text=“We have”,fill=“white”)
self.gamefield.create_text(20100,anchor=W,font=(“Comic Sans MS”,25),text=“had”,fill=“white”)
self.gamefield.create_text(20140,anchor=W,font=(“Comicsans MS”,25),text=“a”,fill=“white”)
self.gamefield.create_text(55140,anchor=W,font=(“Comic Sans MS”,25,“bold”),text=“BAD TIME”,fill=“cyan”)
self.gamefield.create_text(20,180,anchor=W,font=(“Comicsans MS”,25),text=“finding'circles.dat',fill=“white”)
self.gamefield.create_text(20,220,anchor=W,font=(“Comic Sans MS”,25),text=“请放置”,fill=“白色”)
self.gamefield.create_text(20260,anchor=W,font=(“Comic Sans MS”,25),text=“文件在”,fill=“白色”)
self.gamefield.create_text(20300,anchor=W,font=(“Comic Sans MS”,25),text=“与”fill=“white”相同的文件夹)
self.gamefield.create_text(20340,anchor=W,font=(“Comic Sans MS”,25),text=“the file”,fill=“white”)
self.gamefield.create_text(20390,anchor=W,font=(“Comic Sans MS”,25),text=“'my_circle.py'”,fill=“white”)
self.gamefield.pack(side=“top”)
self.root.mainloop()
类别Mycircle:
定义初始化(自):
self.root=Tk()#Tk
self.root.title(“我的圈”)#栏上的名称
self.root.resizeable(0,0)#不允许调整大小
self.gamefield=Canvas(self.root,宽度=640,高度=480,bg=“white”)#Canvas
self.top=Frame(self.root)
self.count=0#count
尝试:
以开放(“圆圈.dat”,“r”)作为f:
self.text=[int(a)表示l中的l,而int(a)表示l中的a.split()]
除:
错误()
当self.count
tkinter应用程序的Tk实例不应超过一个。如果需要其他窗口,则需要创建
Toplevel
的实例,问题是什么?是否要在同一窗口中显示“错误”?