77 lines
3.5 KiB
Python
77 lines
3.5 KiB
Python
|
import tkinter
|
||
|
import tkinter.ttk
|
||
|
import tkinter.filedialog
|
||
|
|
||
|
|
||
|
class Window(tkinter.Tk):
|
||
|
def __init__(self, title='', w=550, h=450, bg=None):
|
||
|
super().__init__()
|
||
|
self.screen_size = {'w': self.winfo_screenwidth(), 'h': self.winfo_screenheight()}
|
||
|
self.w = w
|
||
|
self.h = h
|
||
|
self.geometry('%sx%s+%s+%s' % (self.w, self.h, int(self.screen_size['w'] / 2 - self.w / 2), int(self.screen_size['h'] / 2 - self.h / 2)))
|
||
|
self.iconbitmap('gray75')
|
||
|
self.title(title)
|
||
|
self.config(background=bg)
|
||
|
self.minsize(self.w, self.h)
|
||
|
|
||
|
class _Labels(tkinter.Label):
|
||
|
pass
|
||
|
|
||
|
class _Button(tkinter.Button):
|
||
|
def dis(self):
|
||
|
self.config(state='disabled')
|
||
|
|
||
|
def nor(self):
|
||
|
self.config(state='normal')
|
||
|
|
||
|
class _Entrys(tkinter.Entry):
|
||
|
def set(self, text):
|
||
|
last = self.config().get('state')[-1]
|
||
|
self.config(state='normal')
|
||
|
self.delete(0, 'end')
|
||
|
self.insert('end', text)
|
||
|
self.config(state=last)
|
||
|
|
||
|
class _Option(tkinter.ttk.Combobox):
|
||
|
def set(self, text):
|
||
|
last = self.config().get('state')[-1]
|
||
|
self.config(state='normal')
|
||
|
self.delete(0, 'end')
|
||
|
self.insert('end', text)
|
||
|
self.config(state=last)
|
||
|
|
||
|
def Labels(self, row=0, col=0, rowspan=1, colspan=1, text='', font=None, bg=None, fg=None, w=None, h=None):
|
||
|
this = self._Labels(self, text=text, font=font, bg=bg, fg=fg, width=w, height=h)
|
||
|
this.grid(row=row, column=col, rowspan=rowspan, columnspan=colspan, padx=4, pady=4, sticky='w')
|
||
|
return this
|
||
|
|
||
|
def Entrys(self, row=0, col=0, rowspan=1, colspan=1, text='', font=None, bg=None, fg=None, w=None, h=None, readonly=None):
|
||
|
this = self._Entrys(self, font=font, bg=bg, fg=fg, width=w)
|
||
|
this.insert('end', text)
|
||
|
this.configure(state=('readonly' if readonly else 'normal'))
|
||
|
this.grid(row=row, column=col, rowspan=rowspan, columnspan=colspan, padx=4, pady=4, sticky='w')
|
||
|
return this
|
||
|
|
||
|
def Option(self, row=0, col=0, rowspan=1, colspan=1, data=[], font=None, bg=None, fg=None, w=None, h=None, defaulti=0):
|
||
|
this = self._Option(self, values=data, font=font, background=bg, foreground=fg, width=w, height=h)
|
||
|
this.set(data[defaulti])
|
||
|
this.configure(state='readonly')
|
||
|
this.grid(row=row, column=col, rowspan=rowspan, columnspan=colspan, padx=4, pady=0, sticky='w')
|
||
|
return this
|
||
|
|
||
|
def Button(self, row=0, col=0, rowspan=1, colspan=1, text='', font=None, bg=None, fg=None, w=None, h=None, function=None):
|
||
|
this = self._Button(self, text=text, font=font, bg=bg, fg=fg, width=w, height=h, command=function)
|
||
|
this.grid(row=row, column=col, rowspan=rowspan, columnspan=colspan, padx=4, pady=0, sticky='w')
|
||
|
return this
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
root = Window('标题', w=550, h=450, bg='#202020')
|
||
|
a = root.Labels(row=0, col=0, text='文本', font=('Microsoft Yahei', 10, 'normal'), bg='#202020', fg='#fcfcfc')
|
||
|
b = root.Entrys(row=0, col=1, text='文本', font=('Microsoft Yahei', 10, 'normal'), bg='#fcfcfc', fg='#202020')
|
||
|
c = root.Entrys(row=0, col=2, text='文本', font=('Microsoft Yahei', 10, 'normal'), bg='#fcfcfc', fg='#acacac', readonly=True)
|
||
|
d = root.Option(row=1, col=0, data=['苹果', '香蕉'], font=('Microsoft Yahei', 10, 'normal'), bg='#202020', fg='#acacac', defaulti=-1)
|
||
|
e = root.Button(row=1, col=1, text='按钮', font=('Microsoft Yahei', 10, 'normal'), bg='#202020', fg='#acacac', function=None)
|
||
|
root.mainloop()
|