新手自学了几个月,感觉python能够提高自己的工作效率蛮不错的,对于新手来说很容易上手,并且也能够很快实现自己大部分想要的功能,建议想学编程的菜鸟们可以多多上网学学。用tk写了界面软件,想类似QQ界面靠边停靠的功能,找了些许没有找到python的代码段,后来想了下,其实python里实现起来也是非常简单的。(老手看了如果有建议请多指教)
from tkinter import *
class rollpanel(Tk):
def __init__(self):
super().__init__()
self.width = 200 #面板宽度
self.distance = 15 #伸出来宽度
self.panelrun()
def panelrun(self):
self.title('RollPanel')
the_width, the_height = self.maxsize()
wm_val = '{}x{}+{}+100'.format(self.width, 600, (the_width - self.width))
self.geometry(wm_val)
self.wm_attributes("-topmost", True)
self.bind('<Enter>', self.enter_panel)
self.bind('<Leave>', self.leave_panel)
def leave_panel(self, *args):
the_width, the_height = self.maxsize()
sideX , sideY = self.winfo_x(), self.winfo_y()
if sideX + self.width > the_width - 15:
self.geometry("+%s+%s" % (the_width - self.distance, sideY))
self.update()
def enter_panel(self, *args):
the_width, the_height = self.maxsize()
sideX, sideY = self.winfo_x(), self.winfo_y()
if sideX == the_width - self.distance:
self.geometry("+%s+%s" % (the_width - self.width, sideY))
self.update()
if __name__ == '__main__':
app = rollpanel()
app.mainloop()
|