本文整理汇总了Python中tkinter.Button.grid方法的典型用法代码示例。如果您正苦于以下问题:Python Button.grid方法的具体用法?Python Button.grid怎么用?Python Button.grid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Button
的用法示例。
在下文中一共展示了Button.grid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InfoFrame
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class InfoFrame(Frame):
def __init__(self,master=None, thread=None):
Frame.__init__(self, master)
self.controlThread=thread
self.stringVar=StringVar()
self.grid()
self.createWidgets()
def createWidgets(self):
self.inputText=Label(self)
if self.inputText != None:
self.inputText['textvariable']=self.stringVar
self.inputText["width"] = 50
self.inputText.grid(row=0, column=0, columnspan=6)
else:
pass
self.cancelBtn = Button(self, command=self.clickCancelBtn) # need to implement
if self.cancelBtn !=None:
self.cancelBtn["text"] = "Cancel"
self.cancelBtn.grid(row=0, column=6)
else:
pass
def clickCancelBtn(self):
print("close the InfoDialog")
self.controlThread.setStop()
def updateInfo(self, str):
self.stringVar.set(str)
示例2: initialize
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def initialize(self):
short_label = Label(self, text="Short Name")
short_label.grid(row=0, column=0, sticky="W", padx=5)
self.new_short_box = Entry(self, width=10)
self.new_short_box.focus_set()
self.new_short_box.grid(row=1, column=0, sticky="W", padx=5)
item_label = Label(self, text="Item Name")
item_label.grid(row=0, column=1)
self.new_item_box = Entry(self, width=40)
self.new_item_box.grid(row=1, column=1, sticky="EW")
amount_label = Label(self, text="Amount")
amount_label.grid(row=0, column=2, sticky="EW")
self.new_amount_box = Entry(self, width=5)
self.new_amount_box.grid(row=1, column=2, padx=10, sticky="EW")
cancel_button = Button(self, text="Cancel", width=10, command=self.cancel)
self.bind("<Escape>", self.cancel)
cancel_button.grid(row=3, column=0, pady=10, padx=5, sticky="W")
ok_button = Button(self, text="OK", width=10, command=self.ok)
self.bind("<Return>", self.ok)
ok_button.grid(row=3, column=2, pady=10, sticky="E")
self.bind("<Return>", self.ok)
self.bind("<Escape>", self.cancel)
示例3: CircleBuilderPopup
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class CircleBuilderPopup(BuilderPopup):
"""
Class that launches a popup and collects user data to pass data back to the main window
to build a circle.
"""
def __init__(self, master):
"""
Establish the GUI of this popup
"""
BuilderPopup.__init__(self, master)
self.data = (0, 0)
self.radius = Label(self.top, text="Radius")
self.radius_entry = Entry(self.top, width=self.width, bd=self.bd)
self.center = Label(self.top, text="Center")
self.center_entry = Entry(self.top, width=self.width, bd=self.bd)
self.build_circle_submit = Button(self.top, text="Build!", command=self.cleanup)
self.top.bind("<Return>", self.cleanup)
self.radius.grid(row=0, column=0)
self.radius_entry.grid(row=0, column=1)
self.center.grid(row=1, column=0)
self.center_entry.grid(row=1, column=1)
self.build_circle_submit.grid(row=2, column=0, columnspan=2)
self.top_left = 0
self.bottom_right = 0
self.radius_entry.focus()
def cleanup(self, entry=None):
"""
Collect the data from the user and package it into object variables, then close.
"""
center = complex(0, 0)
if self.center_entry.get():
center = complex(allow_constants(self.center_entry.get()))
self.data = (float(allow_constants(self.radius_entry.get())), center)
self.top.destroy()
示例4: UndoButton
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class UndoButton(Observer):
'''Represent the 'undo' button in the Senku GUI.'''
def __init__(self, game, parent):
'''Constructor of UndoButton. Receive the game and the
parent widget (frame, in this case).'''
Observer.__init__(self)
self._game = game
self._game.add_observer(self, 'UNDO_STACK')
self._button = Button(parent, text='Deshacer', command=self.undo)
self._button.grid(row=1, column=1)
def update(self, aspect, value):
'''The aspect is always UNDO_STACK. If there's no undo
actions, the button will be disabled.'''
if value.is_empty():
self._button.config(state=DISABLED)
else:
self._button.config(state=NORMAL)
def undo(self):
'''Tell the model to perform the undo action, if it's possible.'''
self._game.undo()
示例5: ConfigWindow
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class ConfigWindow(Toplevel):
'''Represent the configuration window.'''
def __init__(self, parent=None):
'''Constructor of ConfigWindow.'''
Toplevel.__init__(self, parent)
self.title('Configuracion')
self._states = [IntVar(value=CONFIG['GAME_TRACKING']),
IntVar(value=CONFIG['CONFIRM_EXIT'])]
self._cbox_gtrack = Checkbutton(self, text='Seguimiento del juego')
self._cbox_gtrack.config(variable=self._states[0])
self._cbox_confexit = Checkbutton(self, text='Confirmacion al salir')
self._cbox_confexit.config(variable=self._states[1])
self._cbox_gtrack.grid(row=0, column=0, sticky=W)
self._cbox_confexit.grid(row=1, column=0, sticky=W)
self._button_cancel = Button(self, text='Cancelar', command=self.destroy)
self._button_cancel.grid(row=3, column=1, sticky=E)
self._button_accept = Button(self, text='Guardar y Salir')
self._button_accept.config(command=self.save_config)
self._button_accept.grid(row=3, column=0, sticky=E)
def save_config(self):
pass
def get_state_game_tracking(self):
return self._states[0].get()
def get_state_confirm_exit(self):
return self._states[1].get()
示例6: setupSelectMachineButtons
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def setupSelectMachineButtons(self):
numDevices = len(self.supportedDevices)
numColumns = 3
numRows = math.ceil((numDevices+1)/3)
self.photo = PhotoImage(file="eguana.gif")
self.photo = self.photo.subsample(2);
self.photo_label = Label(self.selectMachineFrame,image=self.photo,borderwidth=0,highlightthickness=0)
self.photo_label.configure(bg='#FADC46')
self.photo_label.grid(row=int(numRows/2),column=1, sticky=N+S+E+W,padx=2,pady =2)
self.photo_label.image = self.photo
index = 0
for i in range(numRows):
for j in range(numColumns):
if not(j == 1 and i == int(numRows/2)) and (index < numDevices):
device = self.supportedDevices[index]
b = Button(self.selectMachineFrame,text=device.name,relief=RAISED, command=lambda device=device :self.machineButtonPressed(device))
b.grid(row=i,column=j, sticky=N+S+E+W,padx=2,pady =2)
index += 1
for i in range(numRows):
self.selectMachineFrame.rowconfigure(i,weight=1)
for i in range(numColumns):
self.selectMachineFrame.columnconfigure(i,weight=1)
示例7: make_button
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def make_button(self, label, command, isdef=0):
"Return command button gridded in command frame."
b = Button(self.buttonframe, text=label, command=command, default=isdef and "active" or "normal")
cols, rows = self.buttonframe.grid_size()
b.grid(pady=1, row=rows, column=0, sticky="ew")
self.buttonframe.grid(rowspan=rows + 1)
return b
示例8: Application
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+S+E+W)
self.mainframe()
def mainframe(self):
self.data = Listbox(self, bg='red')
self.scrollbar = Scrollbar(self.data, orient=VERTICAL)
self.data.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.data.yview)
for i in range(1000):
self.data.insert(END, str(i))
self.run = Button(self, text="run")
self.stop = Button(self, text="stop")
self.data.grid(row=0, column=0, rowspan=4,
columnspan=2, sticky=N+E+S+W)
self.data.columnconfigure(0, weight=1)
self.run.grid(row=4,column=0,sticky=EW)
self.stop.grid(row=4,column=1,sticky=EW)
self.scrollbar.grid(column=2, sticky=N+S)
示例9: __init__
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class Btn:
def __init__(self, master, row, col, board, play, fun=0):
if fun:
self.button = Button(master, width=1, height=1, command=self.rest, text='rest')
else:
self.button = Button(master, width=1, height=1, command=self.clk)
self.button.grid(row=row, column=col)
self.row = row
self.col = col
self.board = board
self.play = play
self.master = master
def rest(self):
self.play.restart()
def clk(self):
self.button['text'] = self.board.pop_turn()
self.button['state'] = DISABLED
self.board.set_cell(self.row, self.col, self.button['text'])
if self.board.win():
for btn in self.play.btns:
btn.button['state'] = DISABLED
Label(self.master, text='{0} wins!'.format(self.button['text'])).grid(row=4, column=0, columnspan=2)
elif self.board.no_empty():
for btn in self.play.btns:
btn.button['state'] = DISABLED
Label(self.master, text='Draw!'.format(self.button['text'])).grid(row=4, column=0, columnspan=2)
示例10: testThread
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class testThread(threading.Thread):
def __init__(self, dialog, frame, frame2):
super().__init__()
self.dialog=dialog
self.frame=frame
self.frame2=frame2
frame.grid(row=0, column=0, sticky="nsew")
frame2.grid(row=0, column=0, sticky="nsew")
def run(self):
print("In thread.")
self.button = Button(
frame, text="Hellow", fg="red", command=say_hi
)
self.button.grid(row=0, column=0)
qBtn = Button(frame2, text="QUIT", command=frame2.quit)
qBtn.grid(row=0, column=0)
self.dialog.mainloop()
#self.frame.destroy()
print("QUIT")
示例11: draw_grids
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def draw_grids(self):
for x in range (0, self.dimension):
for y in range(0, self.dimension):
handler = lambda x=x,y=y: self.playerMoved(x, y)
button = Button(self.root, command=handler, font=self.font, width=2, height=1)
button.grid(row=x, column=y)
self.buttons[x,y] = button
示例12: __init__
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def __init__(self, client):
# Basic setup
super(Preferences, self).__init__()
self.client = client
# Setup the variables used
self.echo_input = BooleanVar()
self.echo_input.set(self.client.config['UI'].getboolean('echo_input'))
self.echo_input.trace("w", self.echo_handler)
self.logging = BooleanVar()
self.logging.set(self.client.config['logging'].getboolean('log_session'))
self.logging.trace('w', self.logging_handler)
self.log_dir = self.client.config['logging']['log_directory']
# Build the actual window and widgets
prefs = Toplevel(self)
prefs.wm_title("Preferences")
echo_input_label = Label(prefs, text="Echo Input:")
logging_label = Label(prefs, text='Log to file:')
echo_checkbox = Checkbutton(prefs, variable=self.echo_input)
logging_checkbox = Checkbutton(prefs, variable=self.logging)
logging_button_text = 'Choose file...' if self.log_dir == "" else self.log_dir
logging_button = Button(prefs, text=logging_button_text, command=self.logging_pick_location)
# Pack 'em in.
echo_input_label.grid(row=0, column=0)
echo_checkbox.grid(row=0, column=1)
logging_label.grid(row=1, column=0)
logging_checkbox.grid(row=1, column=1)
logging_button.grid(row=1, column=2)
示例13: initUI
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def initUI(self):
self.parent.title("Mario's Picross Puzzle Editor")
self.puzzles = None
# Build the menu
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar)
self.fileMenu = fileMenu
fileMenu.add_command(label="Open Mario's Picross ROM...",
command=self.onOpen)
fileMenu.add_command(label="Save ROM as...",
command=self.onSave,
state=DISABLED)
fileMenu.add_separator()
fileMenu.add_command(label="Exit", command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
# Navigation
Label(self.parent).grid(row=0, column=0)
Label(self.parent).grid(row=0, column=4)
self.parent.grid_columnconfigure(0, weight=1)
self.parent.grid_columnconfigure(4, weight=1)
prevButton = Button(self.parent,
text="<--",
command=self.onPrev,
state=DISABLED
)
self.prevButton = prevButton
prevButton.grid(row=0, column=1)
puzzle_number = 1
self.puzzle_number = puzzle_number
puzzleNumber = Label(self.parent, text="Puzzle #{}".format(puzzle_number))
self.puzzleNumber = puzzleNumber
puzzleNumber.grid(row=0, column=2)
nextButton = Button(self.parent,
text="-->",
command=self.onNext,
state=DISABLED
)
self.nextButton = nextButton
nextButton.grid(row=0, column=3)
# Canvas
canvas = Canvas(self.parent)
self.canvas = canvas
for i in range(15):
for j in range(15):
fillcolor = "gray80"
self.canvas.create_rectangle(10+20*j, 10+20*i,
10+20*(j+1), 10+20*(i+1),
fill=fillcolor,
tags="{},{}".format(i, j)
)
self.canvas.bind("<ButtonPress-1>", self.onClick)
canvas.grid(row=1, columnspan=5, sticky=W+E+N+S)
self.parent.grid_rowconfigure(1, weight=1)
示例14: ingresarUsuario
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
def ingresarUsuario(cls):
cls.nombre=""
def salir():
root.quit()
def cargarArchivo():
cls.nombre=a.get()
root.destroy()
def obtenerN():
n=a.get()
return (n)
root = Tk()
root.title('CargarDatos')
a = StringVar()
atxt = Entry(root, textvariable=a,width=20)
cargar = Button(root, text="Cargar Archivo", command=cargarArchivo,width=15)
salirB= Button(root, text ="Salir", command=root.destroy, width=10)
atxt.grid(row=0, column=0)
cargar.grid(row=1, column=0)
salirB.grid(row=1,column=1)
root.mainloop()
return (obtenerN())
示例15: PyBooguNote
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import grid [as 别名]
class PyBooguNote(Frame):
"""Main class"""
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
self.create_toolbar()
self.sc = ScrolledCanvas(parent, bg="white", highlightthickness=0, takefocus=1)
self.sc.frame.pack(expand=1, fill='both')
def create_toolbar(self):
self.toolbar = Frame(self.parent)
self.btn_new = Button(self.toolbar, text='New', command=self.new_file)
self.btn_new.grid(row=0, column=0)
self.btn_open = Button(self.toolbar, text='Open', command=self.open_file)
self.btn_open.grid(row=0, column=1)
self.toolbar.pack(fill='both')
def open_file(self):
self.file_path = askopenfilename(filetypes=[('BooguNote Files', '.boo')])
self.dom = parse(self.file_path)
curItem = None
pyBt = PyBooguTree(self.sc.canvas, self.file_path, self.dom)
def new_file(self):
self.file_path = asksaveasfilename()
print(self.file_path)