繁体   English   中英

第二个窗口出现在tkinter中

[英]Second window appears in tkinter

但是,当我确定错误部分(仅在circles.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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM