本文整理汇总了Python中Tkinter.Frame.pack_propagate方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.pack_propagate方法的具体用法?Python Frame.pack_propagate怎么用?Python Frame.pack_propagate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.pack_propagate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def __init__(self):
#Creating main window. And initializing components
Tk.__init__(self)
f = Frame(self, width=400, height=200)
f.pack(expand=True)
#Blank labels are added to make window alignment better
Label(f,text="").grid(row=0)
#Blank labels are added to make window alignment better
Label(f,text=" ").grid(row=1,column=0)
#Add label fileName
Label(f,text="File Name").grid(row=1,column=1)
#Adding text box
self.textbox1=Entry(f,width=20)
self.textbox1.grid(row=1,column=2)
#Adding file Browse button. Set its even handler as openFileBrowser()
Button(f,text="Choose File",command=self.openFileBrowser).grid(row=1,column=3)
#Blank labels are added to make window alignment better
Label(f,text=" ").grid(row=1,column=4)
#Blank labels are added to make window alignment better
Label(f,text="").grid(row=2)
#Adding Summarize button. Set its even handler as summarize()
Button(f,text="Summarize",command=self.summarize).grid(row=3,column=2)
#Adding frame to window
f.pack_propagate(0)
#Set window title
self.title("Auto Text Summarizer")
self.mainloop()
示例2: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def __init__(self, master, **kwargs):
Frame.__init__(self, master)
textarea_frame = Frame(self, bd=1, relief=SOLID,**kwargs)
textarea_frame.pack(fill=X)
textarea_frame.pack_propagate(False)
self.textarea = Text(textarea_frame, height=1, pady=self.TAG_ENTRY_PADY, padx=self.TAG_ENTRY_PADX, highlightthickness =0, spacing1=0, spacing2=0, spacing3=0, borderwidth=0, wrap="none")
self.textarea.pack(expand=True, fill=BOTH, padx=2)
scrollbar = Scrollbar(self, orient=HORIZONTAL, command=self.textarea.xview)
scrollbar.pack(fill=X)
self.textarea.configure(xscrollcommand=scrollbar.set)
self.textarea.bind("<KeyPress>",self._on_keypress)
tag = Tag(self.textarea, "")
self.textarea.window_create("1.0", window=tag)
self.update_idletasks()
tag_reqheight = tag.winfo_reqheight()
textarea_frame.configure(height=tag_reqheight + 2*self.TAG_ENTRY_PADY+2*self.textarea["borderwidth"])
# I add a hidden frame because I want the cursor centered including when there is no tag
self.textarea.window_create("1.0", window=Frame(self.textarea, height=tag_reqheight, width=0, borderwidth=0))
tag.destroy()
示例3: new_label
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def new_label(self):
# Creating a new row header
self._number_of_labels += 1
frame_button = Frame(self._frame_of_row_numbers, height=self._row_height)
frame_button.pack()
frame_button.pack_propagate(False)
row_label = Label(frame_button, text =self._number_of_labels, **self._labelrow_kwargs)
row_label.bind("<1>", lambda event, index=self._number_of_labels-1: self._on_click_label(index))
if self._hover_background:
row_label.bind("<Enter>", lambda event, row_label=row_label: row_label.configure(background=self._hover_background))
row_label.bind("<Leave>", lambda event, row_label=row_label: row_label.configure(background=self.cget("background")))
row_label.pack(expand=True, fill=BOTH)
width_of_row_numbers= max(row_label.winfo_reqwidth(), self._row_minwidth)
if width_of_row_numbers > self._width_of_row_numbers:
self._width_of_row_numbers = width_of_row_numbers
for slave in self._frame_of_row_numbers.pack_slaves():
slave.configure(width=width_of_row_numbers)
else:
frame_button.configure(width=width_of_row_numbers)
frame_button.update_idletasks()
self.config(width=self._frame_of_row_numbers.winfo_reqwidth())
self.config(scrollregion=(0, 0, self._frame_of_row_numbers.winfo_reqwidth(), self._number_of_labels*self._row_height))
示例4: UIScoreboard
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [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)
示例5: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def __init__(self, parent, height, width, border_style, border_width, background_colour):
#Call Frams's __init__
Frame.__init__(self, parent)
#create the frame that holds the widgets on the left
lists_frame = Frame(self)
#Add custom ListPane widget
self.lists_list_pane = ListPane(lists_frame, height = 25)
self.lists_list_pane.singleClickFunc = self.displayWords
#Add labels and Buttons
lists_label = Label(lists_frame, text="Word Lists")
import_button = Button(lists_frame, text="Import", command=self.importList)
export_button = Button(lists_frame, text="Export", command=self.exportList)
#Grid everything
lists_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
self.lists_list_pane.grid(row=1, column=0, columnspan=2)
import_button.grid(row=2, column=0, sticky=W, padx=2)
export_button.grid(row=2, column=0)
#create the container frame that holds the widgets on the right
words_frame = Frame(self)
#create custom ListPane widget
self.words_list_pane = ListPane(words_frame,height = 25)
self.words_list_pane.singleClickFunc = self.displayWordInfo
#create labels and buttons
self.speak_word_button = Button(words_frame, text="Speak Word", command=self.speakWord, state=DISABLED)
self.speak_list_button = Button(words_frame,text="Speak List", command=self.speakList, state=DISABLED)
stop_speech_button = Button(words_frame,text="Stop Speech", command=self.stopSpeech)
words_label = Label(words_frame, text="Words in List")
#grid everything
words_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
self.words_list_pane.grid(row=1, column=0, columnspan=3)
self.speak_word_button.grid(row=2, column=0)
self.speak_list_button.grid(row=2, column=1)
stop_speech_button.grid(row=2, column=2)
#Create the infoFrame
info_frame = Frame(self, height=140, width=width, bd=border_width, bg=background_colour, relief=border_style)
self.info_text = Text(info_frame, state=DISABLED, font=tkFont.Font(family="Tahoma", size=9))
self.info_text.pack(fill=BOTH)
lists_frame.grid(column=0, row=0)
words_frame.grid(column=1, row=0)
info_frame.grid(column=0, row=1, columnspan=2)
info_frame.pack_propagate(0)
#Create databse and Festival connections
self.db = SpellingDatabase()
self.fest = FestivalInterface()
list_records = self.db.getLists()
list_names = []
for row in list_records:
list_names.append(row[1])
self.lists_list_pane.display(list_names)
self.words_list_pane.display(['...'])
示例6: init_tk
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def init_tk(self):
self.top = Tk()
self.top.geometry('400x400')
helv36 = tkFont.Font(family='Helvetica', size=36, weight='bold') # you don't have to use Helvetica or bold, this is just an example
f = Frame(self.top, height=200, width=200)
f.pack_propagate(0) # don't shrink
f.pack()
B = Button(f, text ="OK", command = self.helloCallBack)
B['font'] = helv36
B.pack()
self.top.mainloop()
示例7: paintCategories
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [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)
示例8: UIBelote
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [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):
"""
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
class ui:
def __init__(self, r):
self.__root = r # root of program
self.__load_icon = ImageTk.PhotoImage(file=constants.PATH + r'/ico/load.png')
self.__master_file = "" # file to merge into
self.__convert_list = [] # holds list of files to be converted
self.__sub_list = [] # holds list of files to compare against master
self.__convert_opts = None # Top level for additional convert options
self.__nth_number = None # Entry box for holding nth number for convert option
self.__lbl_file = None # Label which holds name of master file in top left corner
self.__convert_lbox = None # Listbox for holding list of files to convert
self.__sub_lbox = None # Listbox for holding list of files to compare against master file
self.__match_rule = IntVar() # the rule on how to merge files into master
self.__column_rule = IntVar() # which column to use for comparing
self.__column_rule.set(1) # initial value is the first column
self.__column_match_rule = IntVar() # which column to compare for a match
self.__column_match_rule.set(1) # initial value is the first column
# public window dimensions
self.width = self.__root.winfo_screenwidth()
self.height = self.__root.winfo_screenheight()
# upper left side of screen
self.__master_frame = Frame(self.__root, width=constants.WIDTH/3, borderwidth=1, relief=SOLID,
height=constants.HEIGHT/4)
self.__master_frame.grid_propagate(False)
self.__master_frame.grid(row=0, column=0, padx=5, pady=5)
# lower left side of screen
self.__convert_frame = Frame(self.__root, width=constants.WIDTH/3, borderwidth=1, relief=SOLID,
height=constants.HEIGHT - constants.HEIGHT/4 - 20)
self.__convert_frame.pack_propagate(False)
self.__convert_frame.grid(row=1, column=0, padx=5, pady=5)
# right side of screen
self.__sub_frame = Frame(self.__root, width=constants.WIDTH - constants.WIDTH/3 - 20, borderwidth=1, relief=SOLID,
height=constants.HEIGHT - 10)
self.__sub_frame.grid_propagate(False)
self.__sub_frame.grid(row=0, column=1, padx=5, pady=5, columnspan=2, rowspan=2)
def setup_gui(self):
"""
Top level function which is called from main(). Sets window title and dimensions, then calls three sub
routines which created and setup the rest of the GUI
"""
self.__root.title('db_swapper')
x = (self.width - constants.WIDTH) / 2
y = (self.height - constants.HEIGHT) / 2
self.__root.geometry('%dx%d+%d+%d' % (constants.WIDTH, constants.HEIGHT, x, y))
self.create_master_frame()
self.create_convert_frame()
self.create_sub_frame()
def create_master_frame(self):
"""
Initialize the GUI for the upper left
"""
load_btn = Button(self.__master_frame, image=self.__load_icon, width=20, height=20,
command=self.import_master_file)
load_btn.grid(row=1, column=1, padx=5, pady=5)
Label(self.__master_frame, text="Master List").\
grid(row=1, column=2, padx=5, pady=5)
self.__lbl_file = Label(self.__master_frame, bg="white", relief=SUNKEN, width=26)
self.__lbl_file.grid(row=2, column=1, padx=5, pady=5, columnspan=3)
# adding these weights allows the GUI to align itself within the frame
self.__master_frame.grid_rowconfigure(0, weight=1)
self.__master_frame.grid_columnconfigure(3, weight=1)
self.__master_frame.grid_rowconfigure(3, weight=1)
self.__master_frame.grid_columnconfigure(0, weight=1)
def create_convert_frame(self):
"""
Initialize the GUI for the lower left side of the program
"""
Label(self.__convert_frame, text="Files to split").\
pack(side=TOP)
self.__convert_lbox = Listbox(self.__convert_frame, width=29, height=12, selectmode=EXTENDED)
self.__convert_lbox.pack(side=TOP)
convert = Button(self.__convert_frame, text="Convert", command=self.choose_convert)
remove = Button(self.__convert_frame, text="Remove Item",
command=lambda: self.remove_item(self.__convert_lbox, self.__convert_list))
load = Button(self.__convert_frame, image=self.__load_icon, width=27, height=20,
command=lambda: self.import_and_append_file(self.__convert_lbox, self.__convert_list))
convert.pack(side=LEFT, padx=(10,5), pady=5)
remove.pack(side=LEFT, padx=(0,5))
load.pack(side=LEFT)
def create_sub_frame(self):
"""
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def __init__(self, parent, height, width, border_style, border_width,
background_colour):
Frame.__init__(self, parent, height=height, width=width)
#Connect to the word/list database
self.db = SpellingDatabase()
self.parent = parent
#Create a frame containing a menu for choosing word category
categorymenu_frame = Frame(self, width=340, height=30, relief=SUNKEN, bd=1)
categorymenu_frame.pack_propagate(0)
categorymenu_label = Label(categorymenu_frame, text="Category:")
wordlist_title = Label(categorymenu_frame, text="Select Words")
#Menu options: one for each category of word
optionList = ("Child", "ESOL", "Spelling Bee", "Custom")
self.category_v = StringVar()
self.category_v.set(optionList[0])
#Command causes word browser to be populated with words from chosen category
self.category_menu = OptionMenu(categorymenu_frame, self.category_v, *optionList, command=self.update_category)
self.category_menu.config(width=10)
self.category_menu.pack(side=RIGHT)
categorymenu_label.pack(side=RIGHT)
wordlist_title.pack(side=LEFT)
#Create frame for the title of the user list panel
userlist_title_frame = Frame(self, width=340, height=30)
userlist_title_frame.pack_propagate(0)
userlist_title = Label(userlist_title_frame, text="Your New List")
userlist_title_frame.grid(column=2, row=0)
userlist_title.pack(side=LEFT)
#Create frame for middle bar containing transfer buttons
middlebar_frame = Frame(self, width = 70, height=400)
middlebar_frame.grid_propagate(0)
#Buttons transfer words from one list to the other
transfer_right_button = Button(middlebar_frame, text="->", command=self.transfer_right)
transfer_left_button = Button(middlebar_frame, text="<-", command=self.transfer_left)
#Press this button to generate a random list from the current category
random_list_button = Button(middlebar_frame, text="Create", command=self.random_list)
random_list_label = Label(middlebar_frame, text="Random\nList")
self.random_list_entry = Entry(middlebar_frame, width=3, justify=RIGHT)
self.random_list_entry.insert(0, 15)
transfer_left_button.grid(column=0, row=1, padx=15, pady=50)
transfer_right_button.grid(column=0, row=0, padx=15, pady=50)
random_list_label.grid(column=0, row=2, pady=3)
self.random_list_entry.grid(column=0, row=3, pady=3)
random_list_button.grid(column=0, row=4, pady=3)
middlebar_frame.grid(column=1, row=1)
#random_list_button.grid(column=0, row=2)
#Create frame for "Add New Word" menu
addword_frame = Frame(self, width=340, height=150, bd=2, relief=SUNKEN)
addword_frame.grid_propagate(0)
addword_label = Label(addword_frame, text = "Add a new word:")
word_label = Label(addword_frame, text="Word:")
def_label = Label(addword_frame, text="Definition:")
use_label = Label(addword_frame, text="Example of Use:")
difficulty_label = Label(addword_frame, text="Difficulty:")
#Entry boxes and an option menu allowing the user to enter attributes of the new word
self.addword_entry = Entry(addword_frame, width = 28)
self.adddefinition_entry = Entry(addword_frame, width=28)
self.adduse_entry = Entry(addword_frame, width=28)
self.difficulty_v = StringVar()
self.difficulty_v.set("1")
difficulty_list = range(1,9)
self.difficulty_menu = OptionMenu(addword_frame, self.difficulty_v, *difficulty_list)
#Pressing this button adds the new word to the database
addword_button = Button(addword_frame, text = "Add", command = self.add_word)
addword_label.grid(row=0, column=0, sticky=W)
addword_button.grid(row=0, column=1, pady=2, sticky=E)
word_label.grid(row=1, column=0, sticky=W)
def_label.grid(row=2, column=0, sticky=W)
use_label.grid(row=3, column=0, sticky=W)
difficulty_label.grid(row=4, column=0, sticky=W)
self.addword_entry.grid(row=1, column=1, pady=2, sticky=E)
self.adddefinition_entry.grid(row=2, column=1, pady=2, sticky=E)
self.adduse_entry.grid(row=3, column=1, pady=2, sticky=E)
self.difficulty_menu.grid(row=4, column=1, pady=2, sticky=E)
addword_frame.grid(column=0, row=2)
#Frame for menu allowing users to save their new lists
savelist_frame = Frame(self, width=340, height=30, bd=2, relief=SUNKEN)
savelist_frame.pack_propagate(0)
savelist_label = Label(savelist_frame, text="List Name:")
#User enters the name of the new list here
self.savelist_entry = Entry(savelist_frame, width=25)
#Pressing this button adds the new list to the database
savelist_button = Button(savelist_frame, text="Save", command = self.save_list)
savelist_label.pack(side=LEFT)
savelist_button.pack(side=RIGHT)
self.savelist_entry.pack(side=RIGHT, padx=5)
savelist_frame.grid(column=2, row=2, sticky=N, pady=5)
#Create list panel for browsing the words stored in database
self.wordbrowse_frame = ListPane(self, height=25)
categorymenu_frame.grid(column=0, row=0)
self.wordbrowse_frame.grid(column=0, row=1, sticky=N)
#Populate the list with words from database
self.update_category()
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
class MyGUI:
def __init__(self):
self.__mainWindow = Tk()
self.outdoor = True
self.indoor = False
self.RWidth=self.__mainWindow.winfo_screenwidth()
self.RHeight=self.__mainWindow.winfo_screenheight()
self.__mainWindow.geometry(("%dx%d")%(self.RWidth,self.RHeight))
self.__mainWindow.maxsize(width=480, height=320)
self.__mainWindow.attributes("-fullscreen", True)
self.but_frame = Frame(self.__mainWindow, pady=5, padx=5, height=60, width=self.RWidth)
self.but_frame.pack(side=BOTTOM, anchor=W)
self.exitbtn = Button(self.but_frame, text="Quit", font=("Helvetica", 14), command=self.__mainWindow.destroy)
self.outdoorbtn = Button(self.but_frame, text="Outdoor", font=("Helvetica", 14), command=self.show_hide_int)
self.indoorbtn = Button(self.but_frame, text="Indoor", font=("Helvetica", 14), command=self.show_hide_int)
self.but_frame.pack_propagate(0)
self.exitbtn.pack(side=LEFT)
self.outdoorbtn.pack(side=RIGHT)
self.indoorbtn.pack(padx=5, side=RIGHT)
self.ext_frame = Frame(self.__mainWindow)
self.ext_frame.pack(side=LEFT)
self.ext_title_label = Label(self.ext_frame, text = 'Outdoor Conditions', font=("Helvetica", 18), pady = 5)
self.ext_title_label.pack(pady=5, side=TOP)
self.ext_cond_frame = Frame(self.ext_frame, height=self.RHeight, width=self.RWidth/4)
self.ext_cond_frame.pack_propagate(0)
self.ext_cond_frame.pack(side=LEFT)
self.ext_initlabelText = 'Temperature: '
self.ext_initLabel = Label(self.ext_cond_frame, text = self.ext_initlabelText, font=("Helvetica", 14))
self.ext_initLabel.pack(padx=5, pady=5, anchor= W)
self.ext_initlabelText = 'Feels like: '
self.ext_initLabel = Label(self.ext_cond_frame, text = self.ext_initlabelText, font=("Helvetica", 14))
self.ext_initLabel.pack(padx=5, pady=5, anchor= W)
self.ext_initlabelText = 'Humidity: '
self.ext_initLabel = Label(self.ext_cond_frame, text = self.ext_initlabelText, font=("Helvetica", 14))
self.ext_initLabel.pack(padx=5, pady=5, anchor= W)
self.ext_cond2_frame = Frame(self.ext_frame, height=self.RHeight, width=self.RWidth/4)
self.ext_cond2_frame.pack_propagate(0)
self.ext_cond2_frame.pack(side=LEFT)
self.ext_temp_labelText = 'Loading...'
self.ext_temp_Label = Label(self.ext_cond2_frame, text = self.ext_temp_labelText, font=("Helvetica", 14))
self.ext_temp_Label.pack(padx=5, pady=5, anchor= W)
self.ext_feels_labelText = 'Loading...'
self.ext_feels_Label = Label(self.ext_cond2_frame, text = self.ext_feels_labelText, font=("Helvetica", 14))
self.ext_feels_Label.pack(padx=5, pady=5, anchor= W)
self.ext_rh_labelText = 'Loading...'
self.ext_rh_Label = Label(self.ext_cond2_frame, text = self.ext_rh_labelText, font=("Helvetica", 14))
self.ext_rh_Label.pack(padx=5, pady=5, anchor= W)
print "Empiezo a mirar el tiempo"
self.__mainWindow.after(1000, self.task)
print "termino de mirar el tiempo"
mainloop()
print "despues del loop"
def show_hide_int(self):
if self.indoor==False:
self.indoor = True
self.draw_int()
print 'indoor true'
else:
self.indoor = False
self.int_frame.pack_forget()
print 'indoor false'
def draw_int(self):
self.int_frame = Frame(self.__mainWindow, pady = 5)
self.int_frame.pack(side=RIGHT)
self.int_title_label = Label(self.int_frame, text = 'Indoor Conditions', font=("Helvetica", 18))
self.int_title_label.pack(pady=5, side=TOP)
self.int_cond_frame = Frame(self.int_frame, height=self.RHeight, width=self.RWidth/4)
self.int_cond_frame.pack_propagate(0)
self.int_cond_frame.pack(side=LEFT)
self.int_initlabelText = 'Temperature: '
self.int_initLabel = Label(self.int_cond_frame, text = self.int_initlabelText, font=("Helvetica", 14))
self.int_initLabel.pack(padx=5, pady=5, anchor= W)
self.int_initlabelText = 'Humidity: '
self.int_initLabel = Label(self.int_cond_frame, text = self.int_initlabelText, font=("Helvetica", 14))
self.int_initLabel.pack(padx=5, pady=5, anchor= W)
self.int_initlabelText = 'Pressure: '
self.int_initLabel = Label(self.int_cond_frame, text = self.int_initlabelText, font=("Helvetica", 14))
self.int_initLabel.pack(padx=5, pady=5, anchor= W)
self.int_initlabelText = 'CO2: '
self.int_initLabel = Label(self.int_cond_frame, text = self.int_initlabelText, font=("Helvetica", 14))
self.int_initLabel.pack(padx=5, pady=5, anchor= W)
self.int_cond2_frame = Frame(self.int_frame, height=self.RHeight, width=self.RWidth/4)
self.int_cond2_frame.pack_propagate(0)
self.int_cond2_frame.pack(side=LEFT)
self.int_temp_labelText = str(self.conditions[4])+ u"\u00b0"+'C'
self.int_temp_Label = Label(self.int_cond2_frame, text = self.int_temp_labelText, font=("Helvetica", 14))
self.int_temp_Label.pack(padx=5, pady=5, anchor= W)
self.int_rh_labelText = str(self.conditions[5])+' %'
self.int_rh_Label = Label(self.int_cond2_frame, text = self.int_rh_labelText, font=("Helvetica", 14))
self.int_rh_Label.pack(padx=5, pady=5, anchor= W)
self.int_pressure_labelText = str(self.conditions[6])+ ' mbar'
self.int_pressure_humidityLabel = Label(self.int_cond2_frame, text = self.int_pressure_labelText, font=("Helvetica", 14))
self.int_pressure_humidityLabel.pack(padx=5, pady=5, anchor= W)
self.int_co2_labelText = str(self.conditions[7])+' ppm'
self.int_co2_Label = Label(self.int_cond2_frame, text = self.int_co2_labelText, font=("Helvetica", 14))
self.int_co2_Label.pack(padx=5, pady=5, anchor= W)
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
def __init__(self, gen, config, preset_dir):
# These will be set later (might consider removing them?)
self.deviceIP = ""
self.devicePort = 0
self.applicationPort = 0
self.config = config
self.preset_dir = preset_dir
self.generator = gen
try:
self.__root = Tk()
screen_w = self.__root.winfo_screenwidth()
screen_h = self.__root.winfo_screenheight()
window_w = self.config["window_width"]
window_h = self.config["window_height"]
off_w = (screen_w - window_w) / 2
off_h = (screen_h - window_h) / 4
# use 4 instead of 2
self.__root.geometry("%dx%d+%d+%d" % (window_w, window_h, off_w, off_h))
# Delete Window callback
self.__root.protocol("WM_DELETE_WINDOW", self.exitCallback)
self.__window = self.__root
self.__root.wm_title("iPhoneComposer")
self.__root.option_add("*tearOff", FALSE)
# Create menu
menubar = Menu(self.__root)
preset_handlers = self.makeShowPresetHandlers()
self.__root.config(menu=menubar)
optionsMenu = Menu(menubar)
menubar.add_cascade(label="Options", menu=optionsMenu)
optionsMenu.add_command(label="Show internal state", command=self.showInternalState)
presetMenu = Menu(menubar)
menubar.add_cascade(label="Presets", menu=presetMenu)
for i in xrange(12):
presetMenu.add_command(label="Show preset %d state" % (i + 1), command=preset_handlers[i])
# Add an output list that may be accessed publicly
mainframe = Frame(self.__window, bd=2, relief=SUNKEN, width=500, height=400)
# Output frame
outputframe = Frame(mainframe, relief=SUNKEN, width=500, height=200)
self.outputscrollbar = Scrollbar(outputframe)
self.outputscrollbar.pack(side=RIGHT, fill=Y)
Label(outputframe, text="Output").pack(side=TOP)
self.output = Text(outputframe, bd=0, yscrollcommand=self.outputscrollbar.set)
self.output.pack(pady=(10, 10), padx=(10, 10))
self.output.configure(yscrollcommand=self.outputscrollbar.set)
self.outputscrollbar.configure(command=self.output.yview)
outputframe.pack_propagate(0)
outputframe.pack(fill=None, expand=False)
# OSC frame
oscframe = Frame(mainframe, relief=SUNKEN, width=500, height=200)
self.oscScrollbar = Scrollbar(oscframe)
self.oscScrollbar.pack(side=RIGHT, fill=Y)
Label(oscframe, text="OSC").pack(side=TOP)
self.osc = Text(oscframe, bd=0, yscrollcommand=self.oscScrollbar.set)
self.osc.pack(pady=(10, 10), padx=(10, 10))
self.osc.configure(yscrollcommand=self.oscScrollbar.set)
self.oscScrollbar.configure(command=self.osc.yview)
oscframe.pack_propagate(0)
oscframe.pack(fill=None, expand=False)
mainframe.pack_propagate(0)
mainframe.grid(row=1, column=0)
# Create the buttons
buttonPane = PanedWindow(self.__window, orient=VERTICAL)
buttonPane.grid(row=2, column=0)
self.__createButtons(buttonPane)
buttonPane.pack_propagate(0)
# Create the connection fields
connectPane = PanedWindow(self.__window, orient=VERTICAL)
connectPane.grid(row=3, column=0)
self.__createConnect(connectPane)
except:
t, v, tb = sys.exc_info()
traceback.print_exception(t, v, tb)
self.__root.quit()
quit()
示例13: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
class Game:
def __init__(self):
self.root = Tk()
self.frame1 = None
self.frame2 = None
self.w = None
self.scoreC = None
self.score = 0
self.hor = True
self.upid = self.downid = self.rightid = self.leftid = 0
self.head = -1
self.time = 700
def home(self):
self.frame1 = Frame(self.root, width=750, height=350, padx=250, bg="black")
self.frame2 = Frame(self.root, height=250, width=750, bg="black", padx=25)
self.root.wm_minsize(width=750, height=666)
self.root.configure(bg="black")
self.frame1.pack_propagate(0)
self.frame1.update()
self.frame1.configure(pady=self.frame1.cget("height") / 2.5)
logo = PhotoImage(file="Game_Logo.gif")
starth = Button(self.frame1, text="Hard", bg="orange", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(40))
startm = Button(self.frame1, text="Medium", bg="teal", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(60))
starte = Button(self.frame1, text="Easy", bg="orange", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(75))
self.frame2.pack_propagate(0)
exp = """ This is a game in which
the arrow keys are used
to move the snake around
and to get points"""
exf = Font(family="comic sans MS", size=20)
Label(self.frame2, image=logo, bg="black", text=exp, padx=10).pack(side="right")
Label(self.frame2, fg="white", bg="black", text=exp, justify="left", font=exf).pack(side="left")
starte.grid(row=0, columnspan=2)
startm.grid(row=0, columnspan=2, column=4, padx=18)
starth.grid(row=0, columnspan=2, column=8)
head = Font(family="comic sans MS", size=30)
self.H=Label(self.root, text="SNAKES", font=head, fg="orange", bg="black", pady=10)
self.H.pack()
self.frame2.pack(expand=True)
self.frame1.pack(expand=True)
self.root.mainloop()
def callgame(self, time):
self.time = time
self.game()
def calldown(self, key):
if self.hor:
self.w.after_cancel(self.leftid)
self.w.after_cancel(self.rightid)
self.down(0)
def callup(self, key):
if self.hor:
self.w.after_cancel(self.leftid)
self.w.after_cancel(self.rightid)
self.up(0)
def callright(self, key):
if not self.hor:
self.w.after_cancel(self.upid)
self.w.after_cancel(self.downid)
self.right(0)
def callleft(self, key):
if not self.hor:
self.w.after_cancel(self.upid)
self.w.after_cancel(self.downid)
self.left(0)
def game(self):
self.score = 0
self.w = Canvas(self.root, width=750, height=500, relief="flat", highlightbackground="grey",
highlightthickness=10)
self.frame1.destroy()
self.frame2.destroy()
self.root.configure(width=1000, padx=10)
self.root.pack_propagate(0)
self.w.configure(background="black")
self.w.pack(side="left")
self.w.create_line(300, 250, 450, 250, width=10, fill="teal")
self.scoreC = Label(self.root, text="Score\n" + str(self.score), bg="black", fg="teal", padx=25, pady=35,
font=Font(family="comic sans MS", size=25))
self.head = self.w.create_line(450, 250, 455, 250, width=10, fill="white")
self.scoreC.pack(side="top")
self.root.bind("<Up>", self.callup)
self.root.bind("<Down>", self.calldown)
self.root.bind("<Right>", self.callright)
self.root.bind("<Left>", self.callleft)
self.createFood()
self.right(0)
def down(self, i):
#.........这里部分代码省略.........
示例14: Chord
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [as 别名]
class Chord(Frame):
RIGHT_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDYwLDB4MDAsMHgwMCwweGUwLDB4MDAsMHgwMCwweGUwLDB4MDMsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MDMsMHgwMCwKMHhlMCwweDAxLDB4MDAsMHg2MCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'
DOWN_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDAwLDB4MDAsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MGYsMHgwMCwweGMwLDB4MDcsMHgwMCwweGMwLDB4MDMsMHgwMCwKMHg4MCwweDAzLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'
def __init__(self, master, title, width, body_background="white", background="#f0f0f0", foreground="#333333", selected_background="#1ba1e2", selected_foreground="white", active_foreground="#0067cb", cursor="hand1"):
Frame.__init__(self, master, background="white")
self._title = title
self._background = background
self._foreground = foreground
self._active_foreground = active_foreground
self._selected_foreground = selected_foreground
self._selected_background = selected_background
self._cursor = cursor
self._right_arrow_icon = BitmapImage(data=base64.b64decode(Chord.RIGHT_ARROW_ICON))
self._down_arrow_icon = BitmapImage(data=base64.b64decode(Chord.DOWN_ARROW_ICON))
self._caption = Frame(self, width =width, background=background, padx=2)
self._caption.pack(fill=X, pady=(0,2))
self._caption.pack_propagate(False)
self._icon_label = Label(self._caption, image=self._right_arrow_icon, background=background)
self._icon_label.pack(side=LEFT)
self._title_label = Label(self._caption, text=title, bg = background, fg=foreground)
self._title_label.pack(side=LEFT, padx=4, fill=X)
self._caption.configure(height= self._title_label.winfo_reqheight())
self.body = Frame(self, background=body_background)
self._body_height = None
self._is_opened = False
self._is_animating = False
self._caption.bind('<Button-1>', self._on_click)
self._title_label.bind('<Button-1>', self._on_click)
self._icon_label.bind('<Button-1>', self._on_click)
self._caption.bind('<Enter>', self._on_enter)
self._caption.bind('<Leave>', self._on_leave)
@property
def title(self):
return self._title
@title.setter
def title(self, text):
self._title = text
self._title_label.configure(text=text)
def _on_enter(self, event):
if not self._is_opened:
self._down_arrow_icon.configure(foreground=self._active_foreground)
self._right_arrow_icon.configure(foreground=self._active_foreground)
self.config(cursor=self._cursor)
def _on_leave(self, event):
if not self._is_opened:
self._down_arrow_icon.configure(foreground=self._foreground)
self._right_arrow_icon.configure(foreground=self._foreground)
self.config(cursor="arrow")
def _on_click(self, event):
if self._is_animating: return
self.toggle()
def open(self):
if self._is_animating: return
if not self._is_opened: self._open()
def _open(self):
self.body.pack()
self.body.pack_propagate(False)
self._icon_label.configure(image=self._down_arrow_icon, background = self._selected_background)
self._title_label.configure(foreground= self._selected_foreground, background = self._selected_background)
self._caption.configure(background = self._selected_background)
self._down_arrow_icon.configure(foreground=self._selected_foreground)
if self._body_height is None:
self._body_height= self.body.winfo_reqheight()
end_value = self._body_height
self.body.configure(width=self.winfo_width())
self._is_opened = True
self._is_animating = True
animation = Animation(
self,
ticks=16,
interval_time=0.01,
#.........这里部分代码省略.........
示例15: isnan
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_propagate [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()