tk不能成为顶级高手

uxh89sit  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(298)

类.py

from tkinter import *
BGCL = '#000000'
CANCELCL = '#800000'
CANCELHOVCL = '#400000'
INFOCL = '#000080'
INFOHOVCL = '#000040'
BARCL = '#004000'
STROKECL = '#00c000'
class FantomForm(Tk):
   def __init__(self):
      Tk.__init__(self)
      self.withdraw()
class MainForm(Tk):
   def __init__(self):
        Tk.__init__(self)
        self['bg'] = BGCL

        self.overrideredirect(True)

        self.bar = Frame(self,bg = BARCL)
        self.bar.place(x = 0 ,y = 0,relwidth = 1,height = 24)
        self.closebtn = Button(self,bg = CANCELCL,fg = BGCL,relief = FLAT,command = self.Exit,bd=0,activebackground = BGCL)
        #print(self.winfo_reqwidth())
        self.closebtn.place(width =24,height = 24,x = self.winfo_reqwidth()-24)

        self.bar.bind("<ButtonPress-1>", self.StartMove)
        self.bar.bind("<ButtonRelease-1>", self.StopMove)
        self.bar.bind("<B1-Motion>", self.OnMotion)
        self.closebtn.bind("<Enter>",self.__closebtne)
        self.closebtn.bind("<Leave>",self.__closebtnl)
   def __closebtne(self,event = None):
      self.closebtn['bg'] = CANCELHOVCL
   def __closebtnl(self,event = None):
      self.closebtn['bg'] = CANCELCL
   def StartMove(self, event = None):
        self.dragx = event.x
        self.dragy = event.y

   def StopMove(self, event = None):
        self.dragx = None
        self.dragy = None

   def OnMotion(self, event = None):
        deltax = event.x - self.dragx
        deltay = event.y - self.dragy
        x = self.winfo_x() + deltax
        y = self.winfo_y() + deltay
        self.geometry("+%s+%s" % (x, y))
   def Exit(self,event = None):
      self.destroy()
class Form(Toplevel):
    def __init__(self,master = None):
        Toplevel.__init__(self,master)
        self['bg'] = BGCL

        self.overrideredirect(True)

        self.bar = Frame(self,bg = BARCL)
        self.bar.place(x = 0 ,y = 0,relwidth = 1,height = 24)
        self.closebtn = Button(self,bg = CANCELCL,fg = BGCL,relief = FLAT,command = self.Exit,bd=0,activebackground = BGCL)
        #print(self.winfo_reqwidth())
        self.closebtn.place(width =24,height = 24,x = self.winfo_reqwidth()-24)

        self.bar.bind("<ButtonPress-1>", self.StartMove)
        self.bar.bind("<ButtonRelease-1>", self.StopMove)
        self.bar.bind("<B1-Motion>", self.OnMotion)
        self.closebtn.bind("<Enter>",self.__closebtne)
        self.closebtn.bind("<Leave>",self.__closebtnl)
    def __closebtne(self,event = None):
      self.closebtn['bg'] = CANCELHOVCL
    def __closebtnl(self,event = None):
      self.closebtn['bg'] = CANCELCL
    def StartMove(self, event = None):
        self.dragx = event.x
        self.dragy = event.y

    def StopMove(self, event = None):
        self.dragx = None
        self.dragy = None

    def OnMotion(self, event = None):
        deltax = event.x - self.dragx
        deltay = event.y - self.dragy
        x = self.winfo_x() + deltax
        y = self.winfo_y() + deltay
        self.geometry("+%s+%s" % (x, y))
    def Exit(self,event = None):
      self.destroy()

main.py

from Classes import *

Form0 = MainForm()
Form1 = Form(MainForm)
Form0.mainloop()
Form1.mainloop()

错误日志
mainform是基于tk的类form是基于toplevel的类我不喜欢默认的windows窗体,所以我自己做了。非常奇怪的错误。我做错了什么?我写这篇文章是因为我不喜欢简短的描述你来自哪里?你喜欢蛋糕吗。。。需要更多的细节。我是费德卡,我来自寒冷、寒冷的俄罗斯,但现在是40摄氏度的好天气,可以计划一场新的战争

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题