本文整理汇总了Python中Tkinter.Frame.place方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.place方法的具体用法?Python Frame.place怎么用?Python Frame.place使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.place方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Color chooser")
self.pack(fill=BOTH, expand=1)
self.btn = Button(self, text="Choose Color",
command=self.onChoose)
self.btn.place(x=30, y=30)
self.frame = Frame(self, border=1,
relief=SUNKEN, width=100, height=100)
self.frame.place(x=160, y=30)
def onChoose(self):
(rgb, hx) = tkColorChooser.askcolor()
self.frame.config(bg=hx)
示例2: initUI
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
def initUI(self):
#top frame using all the remaining space
innerTopFrame = Frame(self, background="black")
innerTopFrame.pack(fill=BOTH, expand=1)
#CLOSE Label
innerBottomLeftFrame = Frame(self, background="black")
innerBottomLeftFrame.place(x=0, width=self.wRoot/2,
y=self.hRoot-200, height=200)
closeLabel = Label(innerBottomLeftFrame, bg="black", fg="black",
text="CLOSE", font=("Comic Sans MS", 48, "bold"))
innerBottomLeftFrame.bind("<Enter>", lambda f: closeLabel.config(fg="white"))
innerBottomLeftFrame.bind("<Leave>", lambda f: closeLabel.config(fg="black"))
innerBottomLeftFrame.bind("<Button-1>", lambda f: self.root.quit())
closeLabel.bind("<Button-1>", lambda f: self.root.quit())
closeLabel.pack(fill=BOTH)
#SHUT DOWN Label
innerBottomRightFrame = Frame(self, background="black")
innerBottomRightFrame.place(x=self.wRoot/2, width=self.wRoot/2,
y=self.hRoot-200, height=200)
shutdownLabel = Label(innerBottomRightFrame, bg="black", fg="black",
text="SHUT DOWN", font=("Comic Sans MS", 48, "bold"))
innerBottomRightFrame.bind("<Enter>", lambda f: shutdownLabel.config(fg="white"))
innerBottomRightFrame.bind("<Leave>", lambda f: shutdownLabel.config(fg="black"))
innerBottomRightFrame.bind("<Button-1>", self.shutdown)
shutdownLabel.bind("<Button-1>", self.shutdown)
shutdownLabel.pack(fill=BOTH)
#design the FullScreenApp
self.pack(fill=BOTH, expand=1)
示例3: UIScoreboard
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class UIScoreboard(object):
"""
Display a scoreboard for the current game
"""
def __init__(self, frame, h_size, v_size):
# Define the size & position
height, width, offset = 40, 100, 80
x, y = h_size - width - offset, 0 + offset - height
# Make a dedicated frame
# This is usefull because label size is in text unit when
# it displays text (*gasp*)
self._frame = Frame(frame, height = height, width = width)
# Avoid shrinking
self._frame.pack_propagate(0)
self._frame.place(x = x, y = y)
# Init the label
self._label = Label(self._frame, text = "", justify = LEFT)
# Pack it and make it fill the frame
self._label.pack(fill = BOTH, expand = 1)
self._score_02 = None
self._score_13 = None
@property
def score_02(self):
return self._score_02
@property
def score_13(self):
return self._score_13
@score_02.setter
def score_02(self, value):
self._score_02 = value
self._update_score_text()
@score_13.setter
def score_13(self, value):
self._score_13 = value
self._update_score_text()
def _update_score_text(self):
name_02 = "Team 0_2"
name_13 = "Team 1_3"
text_02 = str(self._score_02)
text_13 = str(self._score_13)
self._label.config(text = name_02 + ": " + text_02 + "\n" + \
name_13 + ": " + text_13)
示例4: WatcherView
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class WatcherView(object):
def __init__(self, root):
self.top_frame = Frame(root, width=250, height=100)
self.middle_frame = Frame(root, width=100, height=100)
self.top_frame.pack(fill="both", expand=True, padx=20, pady=20)
self.middle_frame.place(in_=self.top_frame, anchor='c', relx=.5, rely=.5)
self.b_toggle_tracking = Button(self.middle_frame)
self.b_toggle_tracking.grid(row=1, column=1, sticky=E)
示例5: paintCategories
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
def paintCategories(self,category_names):
self.canvas.delete("category")
for i,name in enumerate(category_names):
rect = self.getRect(i,0)
x = rect.x1+12
y = rect.y1-70
f = Frame(self.canvas,width=120,height=55)
t = Text(f,bg=utils.bg_blue,fg=utils.mod_question_color,borderwidth=0)
t.tag_config("c",justify=CENTER,font=self.canvas.fonts.getFont("category_font"),wrap=WORD)
t.insert(INSERT,name,"c")
t.config(state=DISABLED)
t.pack(fill=BOTH,expand=True)
f.pack_propagate(False)
f.place(x=x,y=y)
示例6: _build_listbox
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
def _build_listbox(self, values):
listbox_frame = Frame()
self._listbox = Listbox(listbox_frame, background="white", selectmode=SINGLE, activestyle="none", exportselection=False)
self._listbox.grid(row=0, column=0,sticky = N+E+W+S)
self._listbox.bind("<ButtonRelease-1>", self._update_entry_from_listbox)
self._listbox.bind("<Return>", self._update_entry_from_listbox)
self._listbox.bind("<Escape>", lambda event: self.unpost_listbox())
self._listbox.bind('<Control-n>', self._next)
self._listbox.bind('<Control-p>', self._previous)
if self._use_vscrollbar:
vbar = Scrollbar(listbox_frame, orient=VERTICAL, command= self._listbox.yview)
vbar.grid(row=0, column=1, sticky=N+S)
self._listbox.configure(yscrollcommand= lambda f, l: autoscroll(vbar, f, l))
if self._use_hscrollbar:
hbar = Scrollbar(listbox_frame, orient=HORIZONTAL, command= self._listbox.xview)
hbar.grid(row=1, column=0, sticky=E+W)
self._listbox.configure(xscrollcommand= lambda f, l: autoscroll(hbar, f, l))
listbox_frame.grid_columnconfigure(0, weight= 1)
listbox_frame.grid_rowconfigure(0, weight= 1)
x = -self.cget("borderwidth") - self.cget("highlightthickness")
y = self.winfo_height()-self.cget("borderwidth") - self.cget("highlightthickness")
if self._listbox_width:
width = self._listbox_width
else:
width=self.winfo_width()
listbox_frame.place(in_=self, x=x, y=y, width=width)
height = min(self._listbox_height, len(values))
self._listbox.configure(height=height)
for item in values:
self._listbox.insert(END, item)
示例7: ColorWell
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class ColorWell(Frame, ColorTarget):
# holds an RGBA color, but deals with Tk colors
def __init__(self, parent,
color = None,
# color to show in the well
width = 38, height = 38,
# size of well
callback = None,
# method to call upon color change
# [with argument of (WellColor)]
noneOkay = 0,
# can the well return 'none'
multiple = 0,
# does the well currently represent data with multiple colors
wantAlpha = 1
# does the app want alpha supported in this well
):
self._callback = callback
self.noneOkay = noneOkay
self._active = 0
self.wantAlpha = wantAlpha
self._enabled = True
# convert width/height to pixels
width = parent.master.winfo_pixels(width)
height = parent.master.winfo_pixels(height)
borderwidth = int(min(width, height) / 15)
# border is added to width/height, so reduce them
width = width - 2 * borderwidth
height = height - 2 * borderwidth
Frame.__init__(self, parent, width = width, height = height,
borderwidth = borderwidth, relief = Tkinter.RAISED)
self.bind("<Button-1>", self.edgeClick)
self._activeBG = 'white'
self._inactiveBG = self['bg']
# use a Frame around the well interior so that the relief
# doesn't interfere with the interior's canvas coordinate
# system
edgewidth = int(min(width, height) / 12)
self._wellFrame = Frame(self, borderwidth = borderwidth,
relief = Tkinter.SUNKEN)
self._wellFrame.place(x=edgewidth+borderwidth, y=edgewidth+borderwidth,
relwidth=1, relheight=1,
width=0-2*(edgewidth+borderwidth), height=0-2*(edgewidth+borderwidth))
self._well = _WellInterior(self, master=self._wellFrame,
borderwidth=0, highlightthickness=0)
self._well.bind('<Configure>', self._resizeMarkers)
self._well.pack(expand=1, fill="both")
self._wellMarkers = None
if not multiple and color == None and not noneOkay:
# default to black
self.showColor('black', doCallback=0)
else:
self.showColor(color=color, multiple=multiple,
doCallback=0)
def __getattr__(self, name):
# convenience to allow '.rgb[a]' access
if name == "rgb" or name == "rgba":
if self._multiple:
raise AttributeError, "Multiple colors in well"
if self._rgba == None:
if not self.noneOkay:
raise AttributeError, "No color in well"
return None
if name == "rgb":
return self._rgba[:3]
return self._rgba
raise AttributeError, "Unknown attribute '%s'" % name
def edgeClick(self, event):
if not self._enabled:
return
if self._active:
if event.state % 2 == 1:
# 'shift' key depressed
self.deactivate()
else:
# Nothing happens, even if there are more
# than one well selected. Alternative is
# pass
colorPanel().show()
else:
if event.state % 2 == 1:
# 'shift' key depressed
self.activate(exclusive=0)
else:
self.activate(exclusive=1)
def deactivate(self, notifyPanel=1):
if self._active:
if notifyPanel:
#.........这里部分代码省略.........
示例8: Graficar
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
def Graficar(BOLIVIA_var, ECUADOR_var, FRANCIA_var,JAPAN_var, SRILANKA_var, USA_var):
################ Crear Ventana ###############
ventana = Tk()
ventana.geometry("1357x628+0+0")
ventana.title("Pantalla Principal")
image = Image.open('mapas.png')
photo = ImageTk.PhotoImage(image)
label = Label(ventana,image=photo)
label.image = photo
label.pack()
label.place(x=0, y=0, relwidth=1, relheight=1)
button = Button(ventana, text="Exit", command=ventana.destroy)
button.pack()
button.place(width=50,x=10,y=10)
USA_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(USA_Label, text='USA', width=10).pack()
USA_Label.place(width=50,x=20,y=150)
USA_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(USA_N, text=USA_var, width=10).pack()
USA_N.place(width=50,x=20,y=180)
BOLIVIA_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(BOLIVIA_Label, text='Bolivia', width=10).pack()
BOLIVIA_Label.place(width=50,x=200,y=435)
BOLIVIA_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(BOLIVIA_N, text=BOLIVIA_var, width=10).pack()
BOLIVIA_N.place(width=50,x=200,y=465)
ECUADOR_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(ECUADOR_Label, text='Ecuador', width=10).pack()
ECUADOR_Label.place(width=50,x=160,y=355)
ECUADOR_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(ECUADOR_N, text=ECUADOR_var, width=10).pack()
ECUADOR_N.place(width=50,x=160,y=385)
JAPAN_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(JAPAN_Label, text='Japan', width=10).pack()
JAPAN_Label.place(width=50,x=1120,y=150)
JAPAN_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(JAPAN_N, text=JAPAN_var, width=10).pack()
JAPAN_N.place(width=50,x=1120,y=180)
FRANCIA_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(FRANCIA_Label, text='Francia', width=10).pack()
FRANCIA_Label.place(width=50,x=470,y=140)
FRANCIA_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(FRANCIA_N, text=FRANCIA_var, width=10).pack()
FRANCIA_N.place(width=50,x=470,y=170)
SRILANKA_Label = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(SRILANKA_Label, text='SriLanka', width=10).pack()
SRILANKA_Label.place(width=50,x=870,y=340)
SRILANKA_N = Frame(ventana, borderwidth=2, relief=GROOVE)
Label(SRILANKA_N, text=SRILANKA_var, width=10).pack()
SRILANKA_N.place(width=50,x=870,y=370)
ventana.mainloop()
示例9: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
#.........这里部分代码省略.........
'====================================================\n\n'
'Awaiting file selection.')
# Task: Fix menus. They're not working.
self.context_menu = Menu(self.main_frame, tearoff=0)
self.context_menu.add_command(label="Convert", command=self.convert)
self.main_frame.bind("<Button-3>", self.popup)
# - Note: Strangely this stopped anchoring to bottom suddenly, for some
# reason. So it is temporarily disabled.
self.status_bar = Label(self.main_frame,
text='Awaiting file selection.',
bd=1, relief=SUNKEN, anchor=W)
if gui_config['status_bar_on'] is True:
self.status_bar.pack(side=BOTTOM, fill=X)
# Run
root.mainloop()
# Functions
def popup(self, event):
# Note: Currently doesn't work.
self.context_menu.post(event.x_root, event.y_root)
# display the popup menu
try:
self.context_menu.tk_popup(event.x_root, event.y_root, 0)
finally:
# make sure to release the grab (Tk 8.0a1 only)
self.context_menu.grab_release()
def position_main_frame(self, orientation):
if orientation == 'center':
x, y, a = .5, .5, 'c'
return self.main_frame.place(relx=x, rely=y, anchor=a)
elif orientation == 'top':
return self.main_frame.pack()
else:
return self.main_frame.pack()
def on_open(self):
file_types = [
('XLS Files', '*.xls'),
('XLSX Files', '*.xlsx'),
('All files', '*')
]
try:
self.file_selection = tkFileDialog.askopenfilename(
filetypes=file_types, title='Open one or more files.',
message='Open one or more files', multiple=1
)
except:
self.file_selection = tkFileDialog.askopenfilename(
filetypes=file_types, title='Open one or more files.', multiple=1
)
if self.file_selection != '':
self.set_status('Click on Convert to convert files.')
log_output = 'Ready for conversion: \n'
for file in self.file_selection:
log_output += '* ' + str(file) + '\n'
log_output = log_output[:-1] # Removes the last '\n'.
self.log.configure(self.log_text(log_output))
def set_status(self, new_status):
self.status_bar.configure(text=new_status)
def log_text(self, new_text):
示例10: Example
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class Example(Frame):
output_lines = 10
# make debug false when you are actually going to demo this to an audience
debug = 1
def __init__(self, parent):
Frame.__init__(self, parent)
self.hsv_color = colorsys.rgb_to_hsv(0.0, 0.0, 1.0)
self.hex_color = '#0000ff'
# Added second copy of the above two fields for second color
# For debugging, want an initial
if self.debug :
self.hsv_colorTwo = colorsys.rgb_to_hsv(0.0, 0.50, 0.625)
self.hex_colorTwo = '#0088aa'
else:
self.hsv_colorTwo = colorsys.rgb_to_hsv(1.0, 0.0, 0.0)
self.hex_colorTwo = '#ff0000'
self.parent = parent
print "Loading model..."
self.lux = Lux()
self.initUI()
def update_output(self):
(h, s, v) = self.hsv_color
self.cv.set('Color {:.2f} {:.2f} {:.2f} (hsv)'.format(h, s, v))
#tjm Added second update_output method for when second color is chosen
def update_outputTwo(self):
(h, s, v) = self.hsv_colorTwo
self.cvTwo.set('Color {:.2f} {:.2f} {:.2f} (hsv)'.format(h, s, v))
def initUI(self):
row_height = 220
start_height = 30
left_column = 30
sq_size = 180
color_column = left_column
assoc_column = color_column + sq_size + 30
dist_column = assoc_column + 220
y_label = 5
self.parent.title("Interactive LUX visualization")
self.pack(fill=BOTH, expand=1)
self.frame = Frame(self, border=1, relief=SUNKEN, width=sq_size, height=sq_size)
self.frame.place(x=color_column, y=start_height)
self.frame.config(bg=self.hex_color)
self.frame.bind("<Button-1>", self.onChooseClick)
#tjm Added second color display window
self.frameTwo = Frame(self, border=1, relief=SUNKEN, width=sq_size, height=sq_size)
self.frameTwo.place(x=color_column, y=start_height+row_height)
self.frameTwo.config(bg=self.hex_colorTwo)
self.frameTwo.bind("<Button-1>", self.onChooseTwoClick)
#tjm First string field to display the H, S, and V values
self.cv = StringVar()
self.info = Label(self, textvariable=self.cv)
self.info.place(x=color_column, y=y_label)
#tjm second string field to display H, S, and V values
self.cvTwo = StringVar()
self.infoTwo = Label(self, textvariable=self.cvTwo)
self.infoTwo.place(x=color_column, y=y_label+row_height)
#tjm label for associated color terms field
self.cvThree = StringVar()
self.infoThree = Label(self, textvariable=self.cvThree)
self.infoThree.place(x=assoc_column, y=y_label)
#tjm label for distinguishing color terms field
self.cvFour = StringVar()
self.infoFour = Label(self, textvariable=self.cvFour)
self.infoFour.place(x=dist_column, y=y_label)
#tjm instruction text for color term assignment prediction function
self.cvFive = StringVar()
self.infoFive = Label(self, textvariable=self.cvFive)
self.infoFive.place(x=left_column, y=y_label+2*row_height)
self.display = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.display.place(x=assoc_column, y=start_height)
self.display.tag_configure('undistinguished', foreground='dark salmon')
#tjm Added second text window to display color labels
self.displayTwo = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.displayTwo.place(x=assoc_column, y=start_height+row_height)
self.displayTwo.tag_configure('undistinguished', foreground='dark salmon')
#tjm Text field that displays distinction color term for top color
self.distLabel = Text(self, border=1,
relief=SUNKEN, width=25, height=self.output_lines)
self.distLabel.place(x=dist_column, y=start_height)
#.........这里部分代码省略.........
示例11: UIBelote
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class UIBelote(Notify):
"""
Initialise the belote widget
"""
def __init__(self, root, x, y, size_x, size_y):
Notify.__init__(self)
# Memorise the frame
self._root = root
self._frame = Frame(width = size_x, height = size_y)
# No resize
self._frame.pack_propagate(0)
# Style
self._frame.config(borderwidth = 5)
self._x = x
self._y = y
# Init the buttons
self._init_button()
self.enable()
self.clicked = False
def set_position(self, x, y):
self._x = x
self._y = y
def display(self):
"""
Display the widget on the table
"""
self._frame.place(in_ = self._root, x = self._x, y = self._y)
def hide(self):
"""
Hide the pannel when the biddings are closed for example
"""
self._frame.place_forget()
def _init_button(self):
"""
TODO
"""
h = 2
w = 2
self._button = Button(self._frame, text="Belote", \
height=h, width=w, \
command= self._click_belote)
self._button.pack(fill=X)
self._button_clicked = False
def set_button_style(self, clicked):
"""
TODO
"""
fg = 'white' if clicked else 'black'
bg = 'black' if clicked else 'white'
self._button.config(foreground= fg, background= bg)
def _click_belote(self):
"""
TODO
"""
self.clicked = not self.clicked
def disable(self):
"""
Disable the bid button
"""
self._button.config(state = DISABLED)
def enable(self):
"""
Enable the bid button
"""
self._button.config(state = NORMAL)
def belote_ack(self):
"""
#.........这里部分代码省略.........
示例12: TabButton
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class TabButton(Frame):
"""A simple tab-like widget."""
bw = 2 # borderwidth
def __init__(self, name, select_command, tab_row, tab_set):
"""Constructor arguments:
name -- The tab's name, which will appear in its button.
select_command -- The command to be called upon selection of the
tab. It is called with the tab's name as an argument.
"""
Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED)
self.name = name
self.select_command = select_command
self.tab_set = tab_set
self.is_last_in_row = False
self.button = Radiobutton(
self, text=name, command=self._select_event,
padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE,
highlightthickness=0, selectcolor='', borderwidth=0)
self.button.pack(side=LEFT, fill=X, expand=True)
self._init_masks()
self.set_normal()
def _select_event(self, *args):
"""Event handler for tab selection.
With TabbedPageSet, this calls TabbedPageSet.change_page, so that
selecting a tab changes the page.
Note that this does -not- call set_selected -- it will be called by
TabSet.set_selected_tab, which should be called when whatever the
tabs are related to changes.
"""
self.select_command(self.name)
return
def set_selected(self):
"""Assume selected look"""
self._place_masks(selected=True)
def set_normal(self):
"""Assume normal look"""
self._place_masks(selected=False)
def _init_masks(self):
page_set = self.tab_set.page_set
background = page_set.pages_frame.cget('background')
# mask replaces the middle of the border with the background color
self.mask = Frame(page_set, borderwidth=0, relief=FLAT,
background=background)
# mskl replaces the bottom-left corner of the border with a normal
# left border
self.mskl = Frame(page_set, borderwidth=0, relief=FLAT,
background=background)
self.mskl.ml = Frame(self.mskl, borderwidth=self.bw,
relief=RAISED)
self.mskl.ml.place(x=0, y=-self.bw,
width=2*self.bw, height=self.bw*4)
# mskr replaces the bottom-right corner of the border with a normal
# right border
self.mskr = Frame(page_set, borderwidth=0, relief=FLAT,
background=background)
self.mskr.mr = Frame(self.mskr, borderwidth=self.bw,
relief=RAISED)
def _place_masks(self, selected=False):
height = self.bw
if selected:
height += self.bw
self.mask.place(in_=self,
relx=0.0, x=0,
rely=1.0, y=0,
relwidth=1.0, width=0,
relheight=0.0, height=height)
self.mskl.place(in_=self,
relx=0.0, x=-self.bw,
rely=1.0, y=0,
relwidth=0.0, width=self.bw,
relheight=0.0, height=height)
page_set = self.tab_set.page_set
if selected and ((not self.is_last_in_row) or
(self.winfo_rootx() + self.winfo_width() <
page_set.winfo_rootx() + page_set.winfo_width())
):
# for a selected tab, if its rightmost edge isn't on the
# rightmost edge of the page set, the right mask should be one
# borderwidth shorter (vertically)
height -= self.bw
#.........这里部分代码省略.........
示例13: build_left_nav_menu
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
def build_left_nav_menu(self):
app = self.app
main_window = self.app.main_controller.view
player = self.app.game.player
# global left_nav, left_canvas, left
left_nav = Frame(main_window, height=main_window.sh, width=200, background=app.conf.left_nav_background)
left_nav.place(x=0, y=0)
# left = LeftNav(main_window, player, left_nav)
self.selected_planet = player.selected_planet
if isset(player.selected_ship):
self.selected_ship_name = player.selected_ship.name
else:
self.selected_ship_name = ""
self.main_window = main_window
self.selected_ship_id = 0
self.planet_images = []
self.left_canvas = Canvas(left_nav)
self.left_canvas.config(background=app.conf.left_nav_background, highlightthickness=0, height=main_window.sh, width=200)
self.left_canvas.place(x=0, y=0)
if app.conf.debug_lines == 1:
self.left_canvas.create_line(0, 0, 200, main_window.sh, fill='red')
self.left_canvas.create_line(200, 0, 0, main_window.sh, fill='red')
# left nav values
self.logo_image = Image.open(app.conf.title_image_path)
self.logo_image.thumbnail([198, 48], Image.ANTIALIAS)
self.logo_image_res = ImageTk.PhotoImage(self.logo_image)
self.new_planet_image = self.logo_image_res
self.planet_images.append(self.new_planet_image)
self.label_logo = Label(self.left_canvas, image=self.logo_image_res)
self.label_logo.config(background=app.conf.left_nav_background)
self.label_logo.planet_image_res = self.logo_image_res # keep a reference!
self.label_logo.place(anchor='n', x=100, y=0)
# Resources Set
row = 0
self.resources_start_y = 55
self.resources_canvas = Canvas(self.left_canvas)
self.resources_canvas.config(background=app.conf.left_nav_background,
width=198,
highlightthickness=0,
border=0)
self.resources_canvas.grid_propagate(False)
self.resources_canvas.place(anchor='nw', x=0, y=self.resources_start_y)
self.label_resources = Label(self.resources_canvas, text="Resources:", fg=app.conf.main_text_color)
self.label_resources.config(background=app.conf.left_nav_background)
self.label_resources.grid(row=row, column=0, sticky='w')
row += 1
self.label_planets = Label(self.resources_canvas, text="Planets:", fg=app.conf.second_text_color)
self.label_planets.config(background=app.conf.left_nav_background)
self.label_planets.grid(row=row, column=0, sticky='w')
self.label_planets_val = Label(self.resources_canvas, text=str(len(player.owned_planets))
, fg=app.conf.second_text_color)
self.label_planets_val.config(background=app.conf.left_nav_background)
self.label_planets_val.grid(row=row, column=1, sticky='e')
row += 1
self.label_ships = Label(self.resources_canvas, text="Ships:", fg=app.conf.second_text_color)
self.label_ships.config(background=app.conf.left_nav_background)
self.label_ships.grid(row=row, column=0, sticky='w')
self.label_ships_val = Label(self.resources_canvas, text=len(player.ships), fg=app.conf.second_text_color)
self.label_ships_val.config(background=app.conf.left_nav_background)
self.label_ships_val.grid(row=row, column=1, sticky='e')
row += 1
self.label_allies = Label(self.resources_canvas, text="Allies:", fg=app.conf.second_text_color)
self.label_allies.config(background=app.conf.left_nav_background)
self.label_allies.grid(row=row, column=0, sticky='w')
self.label_allies_val = Label(self.resources_canvas, text=len(player.allies), fg=app.conf.second_text_color)
self.label_allies_val.config(background=app.conf.left_nav_background)
self.label_allies_val.grid(row=row, column=1, sticky='e')
row += 1
self.label_enemies = Label(self.resources_canvas, text="Enemies:", fg=app.conf.second_text_color)
self.label_enemies.config(background=app.conf.left_nav_background)
self.label_enemies.grid(row=row, column=0, sticky='w')
self.label_enemies_val = Label(self.resources_canvas, text=len(player.enemies), fg=app.conf.second_text_color)
self.label_enemies_val.config(background=app.conf.left_nav_background)
self.label_enemies_val.grid(row=row, column=1, sticky='e')
row += 1
self.label_separator = Label(self.resources_canvas, text="", fg=app.conf.left_nav_background, width=24)
self.label_separator.config(background=app.conf.left_nav_background)
self.label_separator.grid(row=row, columnspan=2, sticky='e,w')
# left nav buttons
self.left_buttons_start_y = main_window.sh-112
if self.left_buttons_start_y < 500:
self.left_buttons_start_y = 500
self.left_buttons_canvas = Canvas(self.left_canvas)
self.left_buttons_canvas.config(background=app.conf.left_nav_background,
height=200,
#.........这里部分代码省略.........
示例14: isnan
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
tk_root.title('Move tiles to get {}! Score: {}'.format(2048 if max_tile < 2048 else max_tile * 2, score))
for (i, j), value in ndenumerate(grid):
text = '{}'.format('' if isnan(grid[i][j]) else int(grid[i][j]))
font_color = color_map[32][1] if new_tiles[i][j] else color_map['base'] if isnan(value) else color_map[value][0]
labels[4*i+j].config(text=text, fg=font_color, bg=color_map['base'] if isnan(value) else color_map[value][1])
else:
grid, new_tiles, score = game.get_grid(), game.get_new_tiles(), int(game.get_score())
max_tile = int(grid[~isnan(grid)].max())
[labels[i].config(text='' if i < 4 or i > 11 else 'GAMEOVER'[i-4], bg=color_map['base']) for i in xrange(16)]
tk_root.title('Game Over! Tile acheived: {}, Score: {}'.format(max_tile, score))
if __name__ == '__main__':
game, root, window_size = Game2048(), Tk(), 360
root.title('Move tiles to get 2048! Score: 0')
root.geometry('{0}x{0}+111+111'.format(window_size))
root.config(background='#bbada0')
grid, labels = game.get_grid(), []
for (i, j), value in ndenumerate(grid):
frame = Frame(root, width=window_size/4-2, height=window_size/4-2)
font = Font(family='Helvetica', weight='bold', size=window_size/15)
frame.pack_propagate(0)
frame.place(x=j*window_size/4+1, y=i*window_size/4+1)
(text, color) = ('', color_map['base']) if isnan(value) else ('{}'.format(int(value)), color_map[value][0])
label = Label(frame, text=text, font=font, fg=color, bg=color_map['base'] if isnan(value) else color_map[value][1])
label.pack(fill=BOTH, expand=True)
labels.append(label)
root.bind_all('<Key>', lambda event: input_listener(event, game=game, tk_root=root, labels=labels))
root.mainloop()
示例15: UIBidding
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import place [as 别名]
class UIBidding(Notify):
class CoincheException(Exception):
def __init__(self, pid):
self.pid = pid
def __init__(self, root, x, y, size_x, size_y):
Notify.__init__(self)
# Memorise the frame
self._root = root
self._frame = Frame(width = size_x, height = size_y)
# No resize
self._frame.pack_propagate(0)
# Style
self._frame.config(borderwidth = 5)
self._x = x
self._y = y
# Init the buttons
self._init_buttons()
# Will be used to notify the main thread when waiting for a call
self.need_bid_event = Event()
# Will be used to notify the main thread when waiting for a coinche
self.coinche_event = Event()
self.pid = 0
self._last_bid = None
self.enable()
def display(self):
"""
Display the widget on the table
"""
self._frame.place(in_ = self._root, x = self._x, y = self._y)
def hide(self):
"""
Hide the pannel when the biddings are closed for example
"""
self._frame.place_forget()
def _init_color_buttons(self):
"""
Init the buttons to select the color
"""
# Dedicated frame for buttons
self._buttons_frame = Frame()
# This dictionnary will contains all the color buttons
self._buttons = dict()
# Several colors are available
colors = list(Bidding.colors)
colors.pop()
# The buttons need to have a fixed size
h = 2
w = 2
for c in colors:
self._buttons[c] = Button(self._buttons_frame, text=c, \
height=h, width=w, \
command=lambda c=c: self._click_color(c))
self._buttons[c].pack(side = LEFT)
# Pack the dedicated frame into the main frame
self._buttons_frame.pack(in_ = self._frame)
self._selected_color = None
def _init_value_box(self):
"""
Init the list box which select the value of the bid
"""
availableValue = Bidding.values
# TODO: display "pass" instead of "0"
#availableValue[0] = "pass"
self._value_box = Combobox(self._frame, \
values = availableValue, \
# TODO
# Only justify the selected value
#justify = RIGHT, \
state = 'readonly')
self._value_box.bind("<<ComboboxSelected>>", lambda x: self._update_bid_button())
self._value_box.set(availableValue[0])
self._value_box.pack(fill = X)
@staticmethod
#.........这里部分代码省略.........