def __init__(self, root):
self.game = chess_model.game
self.do_replay = False
# photo_images: the PhotoImage objects, one per *type* of piece, that
# are loaded from disk.
self.photo_images = {}
# displayed_images: the actual individual displayed spites, one per
# *piece*, that are each positioned on an actual square.
self.displayed_images = {}
self.custom_font = tkFont.Font(family="{Times}",size=16)
self.bigger_font = tkFont.Font(family="{Times}",size=20)
self.root = root
self.root.title("Stephen's Crazy Chess")
self.root.bind('<Return>', self.start_game)
self.top = ttk.Frame(self.root)
self.top.pack()
self.setup()
self._drag_stuff = {'x': 0, 'y': 0, 'piece': None}
self.center()
python类Font()的实例源码
def body(self, master):
ttk.Style().configure("White.TLabel", background="white")
ttk.Label(master, image=self.logo, justify="center", style="White.TLabel").pack(pady=10)
title = font.Font(family=font.nametofont("TkDefaultFont").cget("family"), size=15, weight="bold")
ttk.Label(master, text=(self.program_title, self.version), font=title, justify="center",
style="White.TLabel").pack()
ttk.Label(master, text=self.description, wraplength=230, justify="center", style="White.TLabel").pack()
ttk.Label(master, text=self.copyright_text, justify="center", style="White.TLabel").pack()
link = pk.Hyperlink(master, text="Visit the project on GitHub", link="https://github.com/DeflatedPickle/Quiver")
link.configure(background="white", justify="center")
link.pack(pady=3)
link._font.configure(size=10)
def _load_browse_data(self):
print("reloading room/zones browse data")
self.data = self._get_room_list()
self.tree.delete(*self.tree.get_children())
self.tree_index = dict()
for idx in range(len(self.dataCols)):
self.tree.column(self.dataCols[idx], width=10)
for item in self.data:
index = self.tree.insert('', 'end', values=item[1:])
self.tree_index[index] = item
if item[2] == 'active':
self.tree.selection_add(index)
for idx in range(len(self.dataCols)-1):
i_width = Font().measure(item[idx+1]) + 10
if self.tree.column(self.dataCols[idx], 'width') < i_width:
self.tree.column(self.dataCols[idx], width=i_width)
def init_SortingButton():
fontemp = font.Font(bo_Frame, size=12, weight='bold')
m1_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black",
text="?? BOX OFFICE ?? ??\n({0} ??)".format(yesterday), command=lambda: searchButtonAction(1))
m1_button.place(x=730, y=5)
m2_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ?? ?",
command=lambda: sortingButtonAction(1))
m2_button.place(x=5, y=350)
m3_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ???",
command=lambda: sortingButtonAction(2))
m3_button.place(x=127, y=350)
m4_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ?? ?",
command=lambda: sortingButtonAction(3))
m4_button.place(x=250, y=350)
m5_button = Button(bo_Frame, font=fontemp, bg="grey", fg="black", text="?? ???",
command=lambda: sortingButtonAction(4))
m5_button.place(x=382, y=350)
def SearchMenu():
global list_movieData, dic_detailData, s1_ListBox, s2_ListBox
global dic_photo, photo
list_movieData = []
dic_detailData = {}
bgLabel = Label(sc_Frame, width=600, height=600, bg='white')
bgLabel.place(x=0, y=0)
init_searchInputLabel()
fontemp = font.Font(sc_Frame, size=12, weight='bold')
s1_ListBox = Listbox(sc_Frame, font=fontemp, width=37, height=18, borderwidth=2, relief='ridge')
s1_ListBox.place(x=5, y=75)
s2_ListBox = Listbox(sc_Frame, font=fontemp, width=37, height=10, borderwidth=2, relief='ridge')
s2_ListBox.place(x=5, y=450)
s1_ListBox.bind('<<ListboxSelect>>', info_event)
def init_loginLabel():
global IDInputLabel, PWInputLabel
fontemp = font.Font(sm_Frame, size=40, weight='bold')
fontemp2 = font.Font(sm_Frame, size=30, weight='bold')
fontemp3 = font.Font(sm_Frame, size=20, weight='bold')
titleLabel = Label(sm_Frame, font=fontemp, text="SEND E-MAIL", bg='white')
titleLabel.place(x=470, y=150)
IDLabel = Label(sm_Frame, font=fontemp2, text="ID", bg='white')
IDLabel.place(x=350, y=250)
IDInputLabel = Entry(sm_Frame, font=fontemp2, width=18, borderwidth=3, relief='ridge', fg='blue')
IDInputLabel.place(x=450, y=250)
PWLabel = Label(sm_Frame, font=fontemp2, text="PW", bg='white')
PWLabel.place(x=335, y=350)
PWInputLabel = Entry(sm_Frame, font=fontemp2, width=18, borderwidth=3, relief='ridge', fg='blue', show='*')
PWInputLabel.place(x=450, y=350)
sendButton = Button(sm_Frame, font=fontemp3, text="Send", command=lambda: sendMail())
sendButton.place(x=600, y=550)
#============================================
def __init__(self, parent, text="", link="https://github.com/DeflatedPickle/pkinter", *args):
ttk.Label.__init__(self, parent, foreground="blue", cursor="arrow", *args)
self.parent = parent
self._text = text
self._link = link
self._font = font.Font(self, self.cget("font"))
self.configure(font=self._font)
if self._text == "":
self.configure(text=self._link)
else:
self.configure(text=self._text)
self.bind("<Enter>", self._enter, "+")
self.bind("<Leave>", self._leave, "+")
self.bind("<Button-1>", self._button, "+")
self.bind("<ButtonRelease-1>", self._button_released, "+")
def _nvimtk_config(self, *args):
'''required config'''
# Hide tkinter cursor
self.config(insertontime=0)
# Remove Default Bindings and what happens on insert etc
bindtags = list(self.bindtags())
bindtags.remove("Text")
self.bindtags(tuple(bindtags))
self.bind('<Key>', self.nvim_handler.tk_key_pressed)
self.bind('<Button-1>', lambda e: self.focus_set())
# The negative number makes it pixels instead of point sizes
size = self.make_font_size(13)
self._fnormal = tkfont.Font(family='Monospace', size=size)
self._fbold = tkfont.Font(family='Monospace', weight='bold', size=size)
self._fitalic = tkfont.Font(family='Monospace', slant='italic', size=size)
self._fbolditalic = tkfont.Font(family='Monospace', weight='bold',
slant='italic', size=size)
self.config(font=self._fnormal, wrap=tk.NONE)
self.nvim_handler._colsize = self._fnormal.measure('M')
self.nvim_handler._rowsize = self._fnormal.metrics('linespace')
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
drt_glue_demo.py 文件源码
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda
作者: SignalMedia
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def __init__(self):
"""Sets up the window and widgets."""
EasyFrame.__init__(self, title = "Image Demo")
self.setResizable(False)
imageLabel = self.addLabel(text = "",
row = 0, column = 0,
sticky = N+S+W+E)
textLabel = self.addLabel(text = "Smokey the cat",
row = 1, column = 0,
sticky = N+S+W+E)
# Load the image and associate it with the image label.
self.image = PhotoImage(file = "smokey.gif")
imageLabel["image"] = self.image
# Set the font and color of the caption.
font = Font(family = "Verdana", size = 20, slant = "italic")
textLabel["font"] = font
textLabel["foreground"] = "blue"
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def insert_ttk_label(self, anchor: tk.W or tk.CENTER or tk.E or str=None, background: str="", font: font.Font=None, foreground: str="", justify: tk.LEFT or tk.CENTER or tk.RIGHT or str=None, padding: list=[], relief: tk.FLAT or tk.RAISED or tk.SUNKEN or tk.GROOVE or tk.RIDGE or str="flat", text: str="", wraplength: int=0, index: int or str="end", *args, **kwargs):
"""Insert a ttk.Label into the game."""
widget = ttk.Label(self.text, anchor=anchor, background=background, font=font, foreground=foreground, justify=justify, padding=padding, relief=relief, text=text, wraplength=wraplength, **kwargs)
self.text.window_create(index, window=widget)
return widget
def __init__(self, textwidget, filetype_name_getter):
self.textwidget = textwidget
self._get_filetype_name = filetype_name_getter
self.pygmentizer = PygmentizerProcess()
# the tags use fonts from here
self._fonts = {}
for bold in (True, False):
for italic in (True, False):
# the fonts will be updated later, see _on_config_changed()
self._fonts[(bold, italic)] = tkfont.Font(
weight=('bold' if bold else 'normal'),
slant=('italic' if italic else 'roman'))
config.connect('pygments_style', self._on_config_changed)
config.connect('font_family', self._on_config_changed)
config.connect('font_size', self._on_config_changed)
self._on_config_changed()
self.textwidget.after(50, self._do_highlights)
def __init__(self, master, title, main, sub, **kwargs):
super().__init__(master=master, **kwargs)
self.configure(borderwidth=3, relief='groove')
self._title_font = font.Font(family='mono', size=-15)
self._main_font = font.Font(family='mono', size=-30, weight='bold')
self._sub_font = font.Font(family='mono', size=-15)
self._title_string = StringVar(value=title)
self._title_label = ttk.Label(self, textvariable=self._title_string, font=self._title_font)
self._main_string = StringVar(value=main)
self._main_label = ttk.Label(self, textvariable=self._main_string, font=self._main_font)
self._sub_string = StringVar(value=sub)
self._sub_label = ttk.Label(self, textvariable=self._sub_string, font=self._sub_font)
self._title_label.grid(column=0, row=0, sticky=N + S + W, padx=15, pady=5)
self._main_label.grid(column=0, row=1, sticky=N + S + W, padx=10, pady=5)
self._sub_label.grid(column=0, row=2, sticky=N + S + W, padx=15, pady=5)
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
def addLine(self, settingsList, dpsFrame):
lineNumber = len(settingsList)
settingsList.append({"transitionValue": "", "color": "#FFFFFF"})
settingsList[lineNumber]["transitionValue"] = tk.StringVar()
settingsList[lineNumber]["transitionValue"].set(str(100*lineNumber))
removeButton = tk.Button(dpsFrame, text="X", command=lambda:self.removeLine(lineNumber, settingsList, dpsFrame))
font = tkFont.Font(font=removeButton['font'])
font.config(weight='bold')
removeButton['font'] = font
removeButton.grid(row=lineNumber, column="0")
lineLabel = tk.Label(dpsFrame, text="Threshold when the line changes color:")
lineLabel.grid(row=lineNumber, column="1")
initialThreshold = tk.Entry(dpsFrame, textvariable=settingsList[lineNumber]["transitionValue"], width=10)
initialThreshold.grid(row=lineNumber, column="2")
initialLabel = tk.Label(dpsFrame, text="Color:")
initialLabel.grid(row=lineNumber, column="3")
colorButton = tk.Button(dpsFrame, text=" ",
command=lambda:self.colorWindow(settingsList[lineNumber], colorButton),
bg=settingsList[lineNumber]["color"])
colorButton.grid(row=lineNumber, column="4")
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def createhand(self):
# create text display
self.textid = self.create_text(self.centrex,
self.centrey - 3*self.blobrad,
fill = 'red',
font = tkf.Font(size = -int(2*self.majortick)))
# create moving and changeable bits
self.handid = self.create_line(self.centrex,self.centrey,
self.centrex - self.handlen,self.centrey,
width = 2*self.linewidth,
fill = 'red')
self.blobid = self.create_oval(self.centrex - self.blobrad,
self.centrey - self.blobrad,
self.centrex + self.blobrad,
self.centrey + self.blobrad,
outline = 'black', fill = 'black')
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def _init_fonts(self, root):
# See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
self._sysfont = Font(font=Button()["font"])
root.option_add("*Font", self._sysfont)
# TWhat's our font size (default=same as sysfont)
self._size = IntVar(root)
self._size.set(self._sysfont.cget('size'))
self._boldfont = Font(family='helvetica', weight='bold',
size=self._size.get())
self._font = Font(family='helvetica',
size=self._size.get())
if self._size.get() < 0: big = self._size.get()-2
else: big = self._size.get()+2
self._bigfont = Font(family='helvetica', weight='bold',
size=big)
def __init__(self, master, label=None):
"""label is function for DrawTree that takes node and returns int."""
self.master = master
self.frame = Toplevel(width=960, height=512)
self.canvas = Canvas(self.frame, width=960, height=512)
# Initialize appropriate fonts to use
DrawTree.smallFont = Font(family='Times', size='14')
DrawTree.largeFont = Font(family='Times', size='24')
self.frame.title("QuadTree Visualization")
self.canvas.pack()
self.label = label
# React to window closure events
self.frame.protocol("WM_DELETE_WINDOW", self.closed)
self.done = False
def initialize_window(self):
"""
Initialize the window of the chat application.
"""
self.master.title("Chappie")
self.master.columnconfigure(0, weight=1)
self.master.columnconfigure(1, weight=4)
self.master.columnconfigure(2, weight=1)
self.master.configure(bg="gray20")
self.master.resizable(0,0)
# Custom Fonts
self.header_font = tkFont.Font(family="Verdana", size=14, weight="bold")
self.default_font = tkFont.Font(family="Verdana", size=10)
# Set size of window and central start location
w = 900
h = 460
sw = self.master.winfo_screenwidth()
sh = self.master.winfo_screenheight()
x = (sw/2) - (w/2)
y = (sh/2) - (h/2)
self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
def __init__(self, master, width=0, height=0, family=None, size=None,*args, **kwargs):
Frame.__init__(self, master, width = width, height= height)
self.pack_propagate(False)
self._min_width = width
self._min_height = height
self._textarea = Text(self, *args, **kwargs)
self._textarea.pack(expand=True, fill='both')
if family != None and size != None:
self._font = tkFont.Font(family=family,size=size)
else:
self._font = tkFont.Font(family=self._textarea.cget("font"))
self._textarea.config(font=self._font)
# I want to insert a tag just in front of the class tag
# It's not necesseary to guive to this tag extra priority including it at the beginning
# For this reason I am making this search
self._autoresize_text_tag = "autoresize_text_"+str(id(self))
list_of_bind_tags = list(self._textarea.bindtags())
list_of_bind_tags.insert(list_of_bind_tags.index('Text'), self._autoresize_text_tag)
self._textarea.bindtags(tuple(list_of_bind_tags))
self._textarea.bind_class(self._autoresize_text_tag, "<KeyPress>",self._on_keypress)
def __init__(self, master, text, background=None, font=None, familiy=None, size=None, underline=True, visited_fg = "#551A8B", normal_fg = "#0000EE", visited=False, action=None):
self._visited_fg = visited_fg
self._normal_fg = normal_fg
if visited:
fg = self._visited_fg
else:
fg = self._normal_fg
if font is None:
default_font = nametofont("TkDefaultFont")
family = default_font.cget("family")
if size is None:
size = default_font.cget("size")
font = Font(family=family, size=size, underline=underline)
Label.__init__(self, master, text=text, fg=fg, cursor="hand2", font=font)
if background is None:
background = get_background_of_widget(master)
self.configure(background=background)
self._visited = visited
self._action = action
self.bind("<Button-1>", self._on_click)
def body(self, master):
style = font.Font(self, size=TITLE_SIZE)
self.status = Label(master, text=self.message, font=style)
self.status.grid(sticky=NSEW, padx=TITLE_SIZE, pady=TITLE_SIZE)
return self.status
def body(self, master):
title = font.Font(self, size=TITLE_SIZE)
legend = font.Font(self, weight='bold')
# Create display variables.
self.category = StringVar(master)
self.question = StringVar(master)
self.answer = StringVar(master)
self.right = StringVar(master)
# Create form labels.
self.c_label = Label(master, textvariable=self.category, font=title)
self.q_label = Label(master, textvariable=self.question)
self.you_answered = Label(master, text='You answered:', font=legend)
self.a_label = Label(master, textvariable=self.answer)
self.right_answer = Label(master, text='Right answer:', font=legend)
self.r_label = Label(master, textvariable=self.right)
# Create control buttons.
options = {'text': '< < <',
'width': TEXT_WIDTH // 2,
'command': self.go_back}
self.back = Button(master, **options)
options = {'text': '> > >',
'width': TEXT_WIDTH // 2,
'command': self.go_next}
self.next = Button(master, **options)
# Display the body.
options = {'sticky': NSEW, 'padx': 5, 'pady': 5}
self.c_label.grid(row=0, column=0, columnspan=2, **options)
self.q_label.grid(row=1, column=0, columnspan=2, **options)
self.you_answered.grid(row=2, column=0, **options)
self.a_label.grid(row=2, column=1, **options)
self.right_answer.grid(row=3, column=0, **options)
self.r_label.grid(row=3, column=1, **options)
self.back.grid(row=4, column=0, **options)
self.next.grid(row=4, column=1, **options)
# Update the labels.
self.update()
def body(self, master):
title = font.Font(self, size=TITLE_SIZE)
legend = {'anchor': W,
'justify': LEFT,
'font': font.Font(self, weight='bold')}
# Create all labels.
text = 'Cumulative score for\nprevious {}:'.format(self.level)
self.explanation = Label(master, text=text, font=title)
self.ruler_one = Label(master, text=(self.RULE * TEXT_WIDTH))
self.answers_right = Label(master, text='Answers right:', **legend)
self.display_right = Label(master, text=str(self.right))
self.answers_wrong = Label(master, text='Answers wrong:', **legend)
self.display_wrong = Label(master, text=str(self.wrong))
self.percent = Label(master, text='Percentage correct:', **legend)
percentage = str(int(100 * self.right / self.total + 0.5)) + '%'
self.display = Label(master, text=percentage)
self.ruler_two = Label(master, text=(self.RULE * TEXT_WIDTH))
# Display the results.
options = {'sticky': NSEW, 'padx': 5, 'pady': 5}
self.explanation.grid(row=0, column=0, columnspan=2, **options)
self.ruler_one.grid(row=1, column=0, columnspan=2, **options)
self.answers_right.grid(row=2, column=0, **options)
self.display_right.grid(row=2, column=1, **options)
self.answers_wrong.grid(row=3, column=0, **options)
self.display_wrong.grid(row=3, column=1, **options)
self.percent.grid(row=4, column=0, **options)
self.display.grid(row=4, column=1, **options)
self.ruler_two.grid(row=5, column=0, columnspan=2, **options)
def setUpClass(cls):
AbstractTkTest.setUpClass.__func__(cls)
try:
cls.font = font.Font(root=cls.root, name=fontname, exists=True)
except tkinter.TclError:
cls.font = font.Font(root=cls.root, name=fontname, exists=False)