本文整理汇总了Python中Tkinter.Frame类的典型用法代码示例。如果您正苦于以下问题:Python Frame类的具体用法?Python Frame怎么用?Python Frame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Frame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class App:
def __init__(self,parent):
# Create frame, buttons, etc
self.f = Frame(parent)
self.f.pack(padx=15,pady=15)
self.entry = Entry(self.f,text="Enter the search term")
self.entry.pack(side= TOP,padx=10,pady=12)
self.entry.bind("<Key>", self.key)
self.entry.focus_set()
self.exit = Button(self.f, text="Exit", command=self.f.quit)
self.exit.pack(side=BOTTOM,padx=10,pady=10)
self.button = Button(self.f, text="Search",command=self.search)
self.button.pack(side=BOTTOM,padx=10,pady=10)
def key(self, event):
# If ENTER was pressed, search
if event.char == '\r':
self.search()
def search(self):
# If there's something to search, search!
if self.entry.get() != '':
self.button.config(text='Searching...', state=DISABLED)
th = SearchThread(self, self.entry.get())
th.start()
else:
tkMessageBox.showinfo('Hey', 'You should type something in the search. That\'s the point, really...')
示例2: __init__
def __init__(self, parent):
# IMAGES #########
self.NODE_IMG = [
ImageTk.PhotoImage(Image.open("img/node1.png")),
ImageTk.PhotoImage(Image.open("img/node2.png")),
ImageTk.PhotoImage(Image.open("img/node3.png")),
ImageTk.PhotoImage(Image.open("img/node4.png")),
]
self.BG = ImageTk.PhotoImage(Image.open("img/map.png"))
self.FLAG_AXIS = ImageTk.PhotoImage(Image.open("img/flag_axis.png"))
self.FLAG_ALLY = ImageTk.PhotoImage(Image.open("img/flag_ally.png"))
self.CANNON = ImageTk.PhotoImage(Image.open("img/cannon.png"))
self.FORTRESS = ImageTk.PhotoImage(Image.open("img/fort.png"))
#################
Frame.__init__(self, parent)
self.parent = parent
self.init_ui()
self.update_ui()
self.update_menu()
示例3: __init__
def __init__( self, parent, net, node, height=10, width=32, title='Node' ):
Frame.__init__( self, parent )
self.net = net
self.node = node
self.prompt = node.name + '# '
self.height, self.width, self.title = height, width, title
# Initialize widget styles
self.buttonStyle = { 'font': 'Monaco 7' }
self.textStyle = {
'font': 'Monaco 7',
'bg': 'black',
'fg': 'green',
'width': self.width,
'height': self.height,
'relief': 'sunken',
'insertbackground': 'green',
'highlightcolor': 'green',
'selectforeground': 'black',
'selectbackground': 'green'
}
# Set up widgets
self.text = self.makeWidgets( )
self.bindEvents()
self.sendCmd( 'export TERM=dumb' )
self.outputHook = None
示例4: __init__
def __init__ (self):
self.app = Tk()
self.app.title('Tic Tac Toe')
#self.app.resizable(width=False, height=False)
#width and hight of window
w = 900
h = 1100
#width and hight of screen
ws = self.app.winfo_screenwidth()
hs = self.app.winfo_screenheight()
#calculate position
x = ws/2 - w/2
y = hs/2 - h/2
#place window -> pramaters(visina, dolzina, pozicija x, pozicija y)
self.app.geometry("%dx%d+%d+%d" % (w,h, x, y))
#======================================
self.frame = Frame() #main frame
self.frame.pack(fill = 'both', expand = True)
self.label = Label(self.frame, text = 'Tic Tac Toe', height = 4, bg = 'white', fg = 'blue')
self.label.pack(fill='both', expand = True)
#self.label2 = Label(self.frame, text = 'here', height = 2, bg = 'white', fg = 'blue') odkomentiri samo za develop-------------
#self.label2.pack(fill='both', expand = True)
self.canvas = Canvas(self.frame, width = 900, height = 900)
self.canvas.pack(fill = 'both', expand = True)
self.framepod = Frame(self.frame)#sub frame
self.framepod.pack(fill = 'both', expand = True)
self.Single = Button(self.framepod, text = 'Start single player', height = 4, command = self.startsingle, bg = 'white', fg = 'blue')
self.Single.pack(fill='both', expand = True, side=RIGHT)
self.Multi = Button(self.framepod, text = 'Start double player', height = 4, command = self.double, bg = 'white', fg = 'blue')
self.Multi.pack(fill='both', expand = True, side=RIGHT)
self.board = AI()
self.draw()
示例5: __init__
def __init__(self, net, parent=None, width=4):
Frame.__init__(self, parent)
self.top = self.winfo_toplevel()
self.top.title("Mininet")
self.net = net
self.menubar = self.createMenuBar()
cframe = self.cframe = Frame(self)
self.consoles = {} # consoles themselves
titles = {"hosts": "Host", "switches": "Switch", "controllers": "Controller"}
for name in titles:
nodes = getattr(net, name)
frame, consoles = self.createConsoles(cframe, nodes, width, titles[name])
self.consoles[name] = Object(frame=frame, consoles=consoles)
self.selected = None
self.select("hosts")
self.cframe.pack(expand=True, fill="both")
cleanUpScreens()
# Close window gracefully
Wm.wm_protocol(self.top, name="WM_DELETE_WINDOW", func=self.quit)
# Initialize graph
graph = Graph(cframe)
self.consoles["graph"] = Object(frame=graph, consoles=[graph])
self.graph = graph
self.graphVisible = False
self.updates = 0
self.hostCount = len(self.consoles["hosts"].consoles)
self.bw = 0
self.pack(expand=True, fill="both")
示例6: __init__
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.pack(fill=TkC.BOTH, expand=1)
self.path = os.path.dirname(os.path.realpath(sys.argv[0]))
self.initialize()
示例7: home
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()
示例8: Example
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)
示例9: __init__
def __init__(self, parent, langton_ant):
Frame.__init__(self, parent)
self.parent = parent
self.pack(fill=BOTH, expand=1)
self.title = self.parent.title()
self.rows = 101
self.columns = 82
self.cell_width = 6
self.cell_height = 6
self.canvas = Canvas(self, width=self.cell_width * self.columns, height=self.cell_height * self.rows,
borderwidth=0, highlightthickness=0)
self.canvas.pack(side="top", fill="both", expand="true")
self.rect = {}
for column in range(self.columns):
for row in range(self.rows):
x1 = column * self.cell_width
y1 = row * self.cell_height
x2 = x1 + self.cell_width
y2 = y1 + self.cell_height
self.rect[row, column] = self.canvas.create_rectangle(x1, y1, x2, y2, fill="white", tags="rect",
outline="black")
self.langton_ant = langton_ant
self.draw_result(500)
示例10: __init__
def __init__(self, parent, scrollbar=True, **kw):
self.parent = parent
frame = Frame(parent)
frame.pack(fill='both', expand=True)
# text widget
Text.__init__(self, frame, **kw)
self.pack(side='left', fill='both', expand=True)
# scrollbar
if scrollbar:
scrb = Scrollbar(frame, orient='vertical', command=self.yview)
self.config(yscrollcommand=scrb.set)
scrb.pack(side='right', fill='y')
# pop-up menu
self.popup = Menu(self, tearoff=0)
self.popup.add_command(label='Cut', command=self._cut)
self.popup.add_command(label='Copy', command=self._copy)
self.popup.add_command(label='Paste', command=self._paste)
self.popup.add_separator()
self.popup.add_command(label='Select All', command=self._select_all)
self.popup.add_command(label='Clear All', command=self._clear_all)
self.bind('<Button-3>', self._show_popup)
示例11: show_source_tree
def show_source_tree(head):
root = Tk()
frame = Frame(root)
frame.pack(fill = 'both')
tree = ttk.Treeview(frame)
#insert root subroutine
# @type head Node
parent_id = tree.insert('', 'end', '', text = head.name)
for child in head.children:
child.insert_to_tree(tree, parent_id)
#add scrollbar
v_scrollbar = Scrollbar(frame, orient = VERTICAL, command = tree.yview)
h_scrollbar = Scrollbar(frame, orient = HORIZONTAL, command = tree.xview)
tree.configure(yscrollcommand = v_scrollbar.set, xscrollcommand = h_scrollbar.set)
v_scrollbar.pack(side = 'right', fill = 'y')
h_scrollbar.pack(side = 'bottom', fill = 'x')
tree.pack(fill = 'both')
root.geometry("600x600")
root.mainloop()
示例12: __init__
def __init__(self,master=None):
# We begin by calling the base class's constructor first
Frame.__init__(self,master)
# We now have an empty window!
# This command sets up a grid structure in the window
self.grid()
# This loop generates rows and columns in the grid
for i in range(13):
self.rowconfigure(i,minsize=10)
for i in range(3):
self.columnconfigure(i,minsize=30)
# These are methods which appear below the constructor
self.defineUnits() # this sets up the units I'll be using in the converter
self.createWidgets() # this places the elements (or widgets) in the grid
# This command "binds" the user's click to a method (varChoice)
# This method will determine which variable the user wants (Distance, Mass, Time)
self.inputlist.bind("<Button-1>",self.__varChoice)
# This is a similar command for the selection of unit
self.unitlist.bind("<Button-1>",self.__unitChoice)
# Finally, this bind reads in whatever value is in the text box when the user hits return
# and carries out the unit conversion
self.inputfield.bind("<Return>",self.__calcConversion)
示例13: __init__
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)
示例14: __init__
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
open_button = Button(self, text = 'Calculate', relief = 'raised',
command=self._on_calculate, width = 23)
open_button.pack()
示例15: __init__
def __init__(self, parent):
Frame.__init__(self, parent, background=Palette.background)
self.parent = parent
self.pack(fill=TkC.BOTH, expand=1)
# init the clock
clock_font = tkFont.Font(family='Droid Sans', size=52, weight='bold')
self.clock = Label(self, text="??:??", fg=Palette.primary, bg=Palette.background, font=clock_font)
self.clock.place(x=0, y=0)
# init the calendar
calendar_font = tkFont.Font(family='Droid Sans', size=12)
self.calendar = Label(self, text="?? ?????, ???", fg=Palette.secondary, bg=Palette.background, font=calendar_font)
self.calendar.place(x=4, y=70)
# init the weather
self.weather = Weather(self, 320, 82)
self.weather.place(x=0, y=(240 - 82))
# init the temperature
temperature_font = tkFont.Font(family='Droid Sans', size=12)
self.temperature = Label(self, text="?? °C", fg=Palette.secondary, bg=Palette.background, font=temperature_font)
self.temperature.place(x=240, y=50)
# print tkFont.families()
# ('Century Schoolbook L', 'Droid Sans Mono', 'Droid Sans Ethiopic', 'Droid Sans Thai', 'DejaVu Sans Mono', 'URW Palladio L', 'Droid Arabic Naskh', 'URW Gothic L', 'Dingbats', 'URW Chancery L', 'FreeSerif', 'DejaVu Sans', 'Droid Sans Japanese', 'Droid Sans Georgian', 'Nimbus Sans L', 'Droid Serif', 'Droid Sans Hebrew', 'Droid Sans Fallback', 'Standard Symbols L', 'Nimbus Mono L', 'Nimbus Roman No9 L', 'FreeSans', 'DejaVu Serif', 'Droid Sans Armenian', 'FreeMono', 'URW Bookman L', 'Droid Sans')
# start working
self.update_clock()
self.update_temperature()
self.fetch_weather_thread()