Botões no GUI tkinter do Python
Você poderá baixar (downloding) desta página em (download)
import tkinter
from tkinter import* class Janela: def __init__(self, instancia_de_Tk): frame1 = Frame(instancia_de_Tk) frame1.pack() e1 = Entry() e1.insert(END, 'Digite um valor') e1.pack() raiz = Tk() Janela(raiz) raiz.mainloop()
from tkinter import* class Janela: def __init__(self, instancia_de_Tk): frame1 = Frame(instancia_de_Tk) frame1.pack() l = Label(frame1, text="Luiz A. Bertolo") l.pack() raiz = Tk() Janela(raiz) raiz.mainloop()
from tkinter import* class Janela: def __init__(self, instancia_de_Tk): principal=Menu(instancia_de_Tk) arquivo=Menu(principal) arquivo.add_command(label="Abrir",command=self.abrir) arquivo.add_command(label="Salvar",command=self.salvar) principal.add_cascade(label="Arquivo",menu=arquivo) principal.add_command(label="Ajuda",command=self.ajuda) instancia_de_Tk.configure(menu=principal) def abrir(self): print ("abrir") def salvar(self): print ("salvar") def ajuda(self) : print ("ajuda") raiz = Tk() Janela(raiz) raiz.mainloop()
import tkinter from tkinter import ttk root = tkinter.Tk() style = ttk.Style() style.map("C.TButton", foreground=[('pressed', 'red'), ('active', 'blue')], background=[('pressed', '!disabled', 'black'), ('active', 'white')] ) colored_btn = ttk.Button(text="Teste", style="C.TButton").pack() root.mainloop()
from tkinter import ttk import tkinter root = tkinter.Tk() style = ttk.Style() style.layout("TMenubutton", [ ("Menubutton.background", None), ("Menubutton.button", {"children": [("Menubutton.focus", {"children": [("Menubutton.padding", {"children": [("Menubutton.label", {"side": "left", "expand": 1})] })] })] }), ]) mbtn = ttk.Menubutton(text='Text') mbtn.pack() root.mainloop()
import tkinter as tk from tkinter import messagebox def main(args): root = tk.Tk() btn= tk.Button(root, text ="Click aqui", command = processaBtn) btn.place(bordermode=tk.OUTSIDE, height=100, width=100) btn1= tk.Button(root, text ="Ou Click aqui", command = processaBtn1) btn1.place(bordermode=tk.OUTSIDE, height=100, width=100,x=100, y=100) return 0 root.mainloop() def processaBtn(): messagebox.showinfo( "OLá", "Você pressionou o botão certo!") def processaBtn1(): messagebox.showinfo( "Ops!!!", "Você pressionou o botão errado!") if __name__ == '__main__': import sys sys.exit(main(sys.argv))
from tkinter import* root = Tk() root.geometry("200x150") frame = Frame(root) frame.pack() MenuBttn = Menubutton(frame, text = "Comida favorita", relief = RAISED) Var1 = IntVar() Var2 = IntVar() Var3 = IntVar() Menu1 = Menu(MenuBttn, tearoff = 0) Menu1.add_checkbutton(label = "Pizza", variable = Var1) Menu1.add_checkbutton(label = "Cheese Burger", variable = Var2) Menu1.add_checkbutton(label = "Salada", variable = Var3) MenuBttn["menu"] = Menu1 MenuBttn.pack() root.mainloop()