def __init__(self, parent, controller): tk.Frame.__init__(self, parent, bg="black", bd=220) self.controller = controller label = tk.Label(self, text="Create Order", fg='#FFFFFF', bg="black", font=controller.title_font) label.pack(side="top", fill="x", pady=10) buttin_1 = tk.button( self, text="Dummy", padx=20, pady=20, fony=controller.buttin_font, command=lambda: controller.show_frame("Create Order")) button_2 = tk.Button( self, text="Go back to Main Menu", padx=20, pady=10, font=controller.button_font, command=lambda: controller.show_frame("StartPage")) button_2.pack(fill=tk.X)
def main(): flag = True #change the words on label def change_label_text(): nonlocal flag flag = not flag color, msg = ('red', 'Hello, world!')\ if flag else ('blue', 'Goodbye, world') label.conflg(text=msg, fg=color) #quit def confirm_to_quit(): if tkinter.massageboc.askokcancel('notice', 'are you sure to quit?'): top.quit() #create the top window top = tkinter.Tk() #set the size of window top.geometry('240*160') #set the title of window top.title('Game') #create the label and add it to the top window label = tkinter.Label(top, text='Hello, world!', font='Arial -32', fg='red') label.pack(expand=1) #create a container to contain the button panel = tkinter.Frame(top) #create a button , attach it to the container, use the parameter of command to attach it to the function button1 = tkinter.Button(panel, text='change', command=change_label_text) button1.pack(side='left') button2 = tkinter.button(panel, text='quit', command=confirm_to_quit) button2.pack(side='right') panel.pack(side='bottom') #start the main loop of issue tkinter.mainloop()
import tkinter #import tkMessageBox top = tkinter.Tk() #def hello(): # tkMessageBox.showinfo("Say Hello", "Hello World") B1 = tkinter.button(top, text="Say Hello", command=hello) B1.pack() top.mainloop()
import tkinter as tk root = tk.Tk() lab = tk.label(root, text="Enter a number:") lab.grid(root, row=0, column=0) ent = tk.Entry(root) ent.grid(row=1, column=0) btn = tk.button(root, text="Press Me") btn.grid(row=2, column=0) output = tk.Text(root) output.configure(state="disable") output.grid(row=0, column=1, rowspan=1) root.mainloop()
app_icon='icon.ico') time.sleep(30) #creating GUI root = tk.Tk() root.geometry("900x800") root.iconbitmao("icon.ico") root.title("CORONA DATA TRACKER INDIA") root.configure(background='white') f = ("poppins", 25, "bold") banner = tk.PhotoImage(file="banner.png") bannerLabel = tk.Label(root, image=banner) bannerLabel.pack() mainlabel = tk.Label(root, text=corona_india(), font=f, bg='white') mainlabel.pack() rebtn = tk.button(root, text="REFRESH", font=f, releif='solid', command=refresh) rebtn.pack() th1 = threading.Thread(target=notify_me) th1.setDaemon(True) th1.start() root.mainloop
import tkinter #import tkMessageBox top = tkinter.Tk() #def hello(): # tkMessageBox.showinfo("Say Hello", "Hello World") B1 = tkinter.button(top, text = "Say Hello", command = hello) B1.pack() top.mainloop()
#images dice = ['die1.png', 'die2.png', 'die3.png', 'die4.png', 'die5.png', 'die6.png'] # simulating the dice with random numbers between # 0 to 6 and generating image DiceImage = ImageTk.PhotoImage(Image.open(random.choice(dice))) #construct a label widget for image ImageLabel = tkinter.Label(root, image=DiceImage) ImageLabel.image = DiceImage #packing a widget in the parent widget ImageLabel.pack(expand=True) def rolling_dice(): DiceImage = ImageTk.PhotoImage(Image.open(random.choice(dice))) #update image ImageLabel.configure(image=DiceImage) # keep a reference imageLabel.image = diceImage button = tkinter.button(root, text='Roll the Dice;', fg='blue', command=rolling_dice) button.pack(expand=True) root.mainloop()
import tkinter as tk root = tk.Tk() output = tk.Text(root, background = "blue", height = 10, width = 50) output.config(state = "disable") output.grid(row = 0, column = 0, columnspan = 2) btnStat1 = tk.button(root, text = "Stat 1") btnStat1.grid(row = 1, column = 0, stick = "NESW") root.mainloop()
import tkinter root = tkinter.Tk() f = tkinter.frame(root) f.pack() l = tkinter.label(f, text='hello world') l.pack() b = tkinter.button(f, text='quit', command=root.destroy()) b.pack()
import tkinter root = Tinker.tk() root.Title("title") def browse(): print("you are browsing") label = tkinter.Label(root, text="label") browseButton = tkinter.button(root, text="button", command=browse) browseButton.Pack() label.Pack() root.mainloop() #pyinstaller --onefile --windowed "file" (in CMD to make py into exe)
import tkinter as tk from tkinter import messagebox top = tk.Tk def helloCallBack(): tk.messagebox.showinfo("Hello Python", "Hello World") button = tk.button(top, text="Hello", command=helloCallBack) button.pack() top.mainloop()
import tkinter m = tkinter.Tk() m.mainloop() import tkinter as tK r = tK.Tk() r.title('Counting Seconds') button = tK.button(r, text='Stop', width=25, command=r.destroy) button.pack() r.mainloop()
ani1 = animation.FuncAnimation(fig, update1, N, fargs=(data1, line1), interval=10000 / N, blit=False) plt.show() if __name__ == '__main__': # Creación de Ventanas root = tk.Tk() root.wm_title("Tarea 02 (15%)") root.geometry("800x600") # Crear frame contenedor de los elementos frame = tk.Frame(root) frame.pack(padx=20, pady=20) # Añadir titulo label = tk.Label(frame, text="Curvas Paramétricas Famosas", height="2") label.pack(fill=tk.X, expand=1) imagen = tk.PhotoImage(file="image.jpg") boton = tk.button(master=frame, text="Curva Bicilindrica", command=Bicilindrica, image=imagen) boton.pack(side=tk.BOTTOM, padx=10, pady=10) tk.mainloop()
import tkinter as tk root = tk.Tk() tk.label(root, text="bar do ze atomaick").pack() tk.button() root.mainloop()
import tkinter as tk from tkinter import * import webbrowser def google(): webbrowser.open("") def facebook(): webbrowser.open("") igoogle = PhotoImage(file="") google = tk.button(win, image=igoogle, command=google) google.grid(row=0, column=0) iyoutube = PhotoImage(file="") youtube = tk.button(win, image=iyoutube, command=youtube) youtube.grid(row=0, column=1)
import tkinter as tk import tkinter.filedialog as fd import PIL.Image import PIL.ImageTk def dispPhoto(path): #画像を読み込む newImage = PIL.Image.open(path).resize((300, 300)) #そのイメージをラベルに表示する imageDate = PIL.ImageTk.PhotoImage(newImage) imageLabel.configure(image=imageDate) imageLabel.image = imageDate def openFile(): fpath = fd.askopenfilename() if fpath: dispPhoto(fpath) root = tk.Tk() root.geometry("400x350") btn = tk.button(text="ファイルを開く", command=openFile) imageLabel = tk.Label() btn.pack() imageLabel.pack() tk.mainloop()
import tkinter tkinter.button()
def get_winner(call): if random.random() <= (1 / 3): throw = "stone" elif (1 / 3) < random.random() <= (2 / 3): throw = "scissors" else: throw = "paper" if (throw == "stone" and call == "paper") or ( throw == "paper" and call == "scissors") or (throw == "scissors" and call == "stone"): stats.append('w') result = "you win!" elif throw == call: stats.append('D') result = "its a draw" else: stats.append('L') result = "you lost!" global output output.config(text="computer did: " + throw + "\n" + result) def pass_s(): get_winner("scissors") def pass_r(): get_winner("stone") def pass_p(): get_winner("paper") window = tkinter.Tk() scissors = tkinter.button(window, text="scissors", bg="#ff9999", padx=10, pady=5, command=pass_s, width=20) stone = tkinter.button(window, text="stone", bg="#80ff80", padx=10, pady=5, command=pass_r, width=20) paper = tkinter.button(window, text="paper", bg="#3399ff", padx=10, pady=5, command=pass_p, width=20) output = tkinter.Label(window, width=20, fg="red", text="what's your call?") scissors.pack(side="left") stone.pack(side="left") paper.pack(side="left") output.pack(side="right") window.mainloop() for i in stats: print(i, end=" ") if stats.count('L') > stats.count('W'): result = "\nyou lost the series." elif stats.count('L') > stats.count('W'): result = "\n series ended with a draw." else: result = "\n you won the series." print(result)
def setupui(self): #Left menu bar left_f = tk.Frame(self, height=self.framedispheight, width=self.leftframewidth) left_f.pack(side=tk.LEFT) #Names and positions of various function buttons btnopen = tk.Button(left_f, text="open image", command=self.openanddisplayimage) btnopen.place(y=25, x=30, width=300, height=self.btnheight) btntrans = tk.Button(left_f, text="process image", command=self.ontransrawimagebtnclicked) btntrans.place(y=85, x=30, width=300, height=self.btnheight) l_selrect = tk.Label(left_f, text="mouse selected") l_selrect.place(x=0, y=165, width=self.leftframewidth, height=self.labeltextheight) "" "List" "" self.l_box = tk.Listbox(left_f) #create two list components self.l_box.place(x=0, y=165 + self.labeltextheight, width=self.leftframewidth, height=270) self.l_box.bind('<listboxselect>', self.onrectlistboxselect) self.drawlistbox() #Delete selected btndel = tk.button(left_f, text="delete selected", command=self.deleteselecteditemfromlistbox) btndel.place(y=460, x=30, width=300, height=self.btnheight) btnsave = tk.button(left_f, text="Save result", command=self.onsavetransrawimagebtnclicked) btnsave.place(y=550, x=30, width=300, height=self.btnheight) #Right image display bar right_f = tk.frame(self, height=self.framedispheight, width=self.imagedispwidth) right_f.pack(side=tk.right) l_rawt = tk.label(right_f, text="raw image") l_rawt.place(x=0, y=0, width=self.imagedispwidth, height=self.labeltextheight) self.image_l_raw = tk.label(right_f, relief="ridge") self.image_l_raw.place(x=0, y=self.labeltextheight, width=self.imagedispwidth, height=self.imagedispheight) self.image_l_raw.bind("<button-1>", self.rawimagelabelclicked) l_transt = tk.label(right_f, text="Processed image") l_transt.place(x=0, y=self.labeltextheight + self.imagedispheight, width=self.imagedispwidth, height=self.labeltextheight) self.image_l_trans = tk.label(right_f, relief="ridge") self.image_l_trans.place(x=0, y=self.labeltextheight + self.imagedispheight + self.labeltextheight, width=self.imagedispwidth, height=self.imagedispheight)
top.title('Calculator') def add(): pass def sub(): pass def multiply(): pass def divide(): pass def display(): pass def delete(): pass b1 = tk.button(top, text='1', command=print('1')) top.mainloop()
# In[ ]: add task_button = tk.Button(root, text='Add Task', command=add_task_width=45, font=('Helvetica', 10), bg='#ede3d9', fg='#000000', relief=tk.FLAT) add_task_button.pack() # In[ ]: delete_task_button = tk.Button(root, text='Delete Task', command = del_task, width=45, font=('Helvetica',10), bg='#ede3d9', fg='#000000',relief=tk.FLAT) delete_task_button.pack() # In[ ]: clear_task_button = tk.button(root, text='Load Tasks', command=load_tasks, width=45, font('Helvetica',10), bg='#ede3d9', fg='#000000', relief=tk.FLAT) clear_task_button.pack() # In[ ]: root.main.loop()
def get_color(r, g, b): """ Retourne une couleur à partir de ses composantes r, g, b entre 0 et 255""" return '#{:02x}{:02x}{:02x}'.format(r, g, b) def ecran_aleatoire(): color = get_color(rd.randint(0, 255), rd.randint(0, 255), rd.randint(0, 255)) root = tk.Tk() bouton_aleatoire = tk.button(root, text="aléatoire", bg="grey100", fg="blue", padx=20, font=("Times", "20"), commad=ecran_aleatoire) bouton_gris_deg = tk.button(root, text="dégradé gris", bg="grey100", fg="blue", padx=20, font=("Times", "20")) bouton_gris_2d = tk.button(root, text="dégradé 2D", bg="grey100", fg="blue", padx=20, font=("Times", "20"))