def init_window(self): self.master.title("MDitor") self.pack(fill=BOTH, expand=1) self.inputeditor = Text(self, width="1") self.inputeditor = Text(self, width="1", font=self.myfont) self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT) # For output window self.outputbox = HTMLLabel(self, width="1", background="lightgray", html="START TYPING TO SEE OUTPUT...") self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT) self.outputbox.fit_height() # change output as we type self.inputeditor.bind("<<Modified>>", self.onInputChange) # ctrl-s shortcut self.inputeditor.bind('<Control-s>', self.savefile) # ctrl-o shortcut self.inputeditor.bind('<Control-o>', self.openfile) # ctrl-h shortcut self.inputeditor.bind('<Control-h>', self.md2html) # File and Open self.mainmenu = Menu(self) self.filemenu = Menu(self.mainmenu) self.filemenu.add_command(label="Open", command=self.openfile) self.filemenu.add_command(label="Save as", command=self.savefile) self.filemenu.add_separator() self.filemenu.add_command(label="Exit", command=self.quit) self.mainmenu.add_cascade(label="File", menu=self.filemenu) self.mainmenu.add_cascade(label="Save HTML", command=self.md2html) self.master.config(menu=self.mainmenu)
def display_searching(self): if type(self.display_frame) is tkinter.Frame: self.display_frame.destroy() self.display_frame = tkinter.Frame(self.right) self.display_frame.pack(side='top',fill=BOTH,expand=1) self.canvas = tkinter.Canvas(self.display_frame) self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1) self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview) self.scrollbar.pack(side='right',fill=tkinter.Y) self.canvas.configure(yscrollcommand=self.scrollbar.set) self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all"))) self.sec_frame = tkinter.Frame(self.canvas) self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385) self.htmlsnippet = ''' <div style="background-color:white;"> <h5 style="color: orange">Searching for top results ...</h5> </div> ''' # HTML template for Searching Message. self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white') self.msg_display.pack()
class Section(Frame): def __init__(self,parent,snippet,source,link): Frame.__init__(self,parent) self.html_code = f""" <h5> Source : <b style="color:red"> {source} </b> </h5> <a href="{link}">original code link</a> """ self.source = HTMLLabel(self,html=self.html_code,height=5,background='white') self.source.pack(side='top') self.snippet = snippet self.code = Text(self, wrap='none', undo=1,background='black',fg='white',height=10) self.code.tag_configure("bigfont", font=("Helvetica", "24", "bold")) self.code.pack(side='top') self.code.insert(END,snippet) self.code.config(state=DISABLED) self.code_syntax_color=ColorLight.ColorLight(txtbox=self.code) self.code_syntax_color.trigger() self.copy = Button(self,text='COPY',command=self.copy_code) self.copy.pack(side='top') def copy_code(self): pyperclip.copy(self.snippet)
def __createHTMLFrame(self, __w, __h, code): from tkhtmlview import HTMLLabel html = HTMLLabel(self.__HTMLviewer, html=code, width=__w, height=__h - 140) html.pack(side=BOTTOM)
def init_window(self): self.master.title('Mardown Viewer') self.pack(fill=tk.BOTH, expand=1) self.mainmenu = tk.Menu(self) self.filemenu = tk.Menu(self.mainmenu) self.filemenu.add_command(label='Open', command=self.openfile) self.filemenu.add_separator() self.filemenu.add_command(label='Exit', command=self.quit) self.mainmenu.add_cascade(label='File', menu=self.filemenu) self.master.config(menu=self.mainmenu) self.outputbox = HTMLLabel(self, width='1', background='white', html='<h1>Welcome</h1>') self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT) self.outputbox.fit_height()
def search_thread(self,command): self.display_searching() # Display Searching Message. self.snippets = search_web(command) # Get Code Snippets self.display_frame.destroy() # destroy existing display frame. # create Display Frame for displaying Search Query and Code Snippets. self.display_frame = tkinter.Frame(self.right) self.display_frame.pack(side='top',fill=BOTH,expand=1) self.canvas = tkinter.Canvas(self.display_frame) self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1) self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview) self.scrollbar.pack(side='right',fill=tkinter.Y) self.canvas.configure(yscrollcommand=self.scrollbar.set) self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all"))) self.sec_frame = tkinter.Frame(self.canvas) self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385) self.htmlsnippet = f''' <div style="background-color:white;"> <h5 style="color: green">Recieved Command</h5> <p>{command}</p> </div> ''' # HTML template for recieved message. self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white') self.msg_display.pack() self.separator = Label(self.sec_frame,text='--------------------------------------------------------------') self.separator.pack(side='top',fill='x',expand='no') # Display Code snippets. for i in range(len(self.snippets)): if len(self.snippets[i][2]) > 0: frami = Section(self.sec_frame,self.snippets[i][2],self.snippets[i][0],self.snippets[i][1]) frami.pack(side='top',fill='x',expand=1) self.sections.append(frami) # Update Controller. self.controller.geometry("1361x600") self.controller.update() self.controller.geometry("1360x600") self.controller.update()
def init_window(self): self.pack(fill=BOTH, expand=1) self.inputeditor = Text(self, width="1", font=self.myfont, bg='black', insertbackground='white', fg='white', wrap=WORD) self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT) self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Welcome</h1>") self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT) self.outputbox.fit_height() self.inputeditor.bind("<<Modified>>", self.onInputChange) self.mainmenu = Menu(self.master.master) self.filemenu = Menu(self.mainmenu) self.filemenu.add_command(label="Open", command=self.openfile) self.filemenu.add_command(label="Save as", command=self.savefile) self.filemenu.add_separator() self.filemenu.add_command(label="Exit", command=self.quit) self.mainmenu.add_cascade(label="File", menu=self.filemenu) self.master.master.config(menu=self.mainmenu)
def __init__(self): # make the sticky sized window appear in the top right corner x = self.root.winfo_screenwidth() - self.width - 10 self.root.geometry("%dx%d+%d+%d" % (self.width, self.height, x, self.y)) # add gui elements self.widgets["counter"] = Label(self.root, text="") self.widgets["counter"].pack() self.widgets["html_label"] = HTMLLabel(self.root, html="") self.widgets["html_label"].pack(fill="both", expand=True) self.widgets["html_label"].fit_height() self.widgets["bottomButtons"] = Frame(self.root) self.widgets["bottomButtons"].pack(side=BOTTOM) # make buttons to paginate through step list self.widgets["prev_button"] = Button(self.widgets["bottomButtons"], text="<", command=self.prev_step) self.widgets["prev_button"].grid(row=0, column=0) self.widgets["open_button"] = Button(self.widgets["bottomButtons"], text="o", command=self.open_file) self.widgets["open_button"].grid(row=0, column=1) self.widgets["next_button"] = Button(self.widgets["bottomButtons"], text=">", command=self.next_step) self.widgets["next_button"].grid(row=0, column=2) self.root["background"] = "#f1f58f" for widget in self.widgets: #print("widget: %s - widget type: %s" % (widget, type(widget))) self.widgets[widget].configure(bg="#f1f58f", bd=0, relief=FLAT) # because html_label only picks up color after the configure for some reason self.widgets["html_label"].set_html("") self.root.bind("<h>", lambda e: self.help_message()) self.root.bind("<o>", lambda e: self.open_file()) self.root.bind("<e>", lambda e: self.edit_file()) self.root.bind("<Right>", lambda e: self.next_step()) self.root.bind("<Left>", lambda e: self.prev_step()) self.root.bind("<g>", lambda e: self.goto_step_number()) self.root.bind("<Control-q>", lambda e: self.root.destroy()) self.keybindings = dict() self.keybindings["h"] = "Show keybindings" self.keybindings["o"] = "Open local file" self.keybindings["e"] = "Edit file" self.keybindings["Right"] = "Go to next step" self.keybindings["Left"] = "Go to previous step" self.keybindings["g"] = "Go to step [number]" self.keybindings["Control-q"] = "Quit"
def init_window(self): self.master.title("Markdown 编辑器") self.pack(fill=BOTH, expand=1) self.inputeditor = Text(self, width="1", font=self.myfont) self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT) self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Markdown 编辑器</h1>") self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT) self.outputbox.fit_height() self.inputeditor.bind("<<Modified>>", self.onInputChange) self.mainmenu = Menu(self) self.filemenu = Menu(self.mainmenu) self.filemenu.add_command(label="打开", command=self.openfile) self.filemenu.add_command(label="另存为", command=self.savefile) self.filemenu.add_separator() self.filemenu.add_command(label="退出", command=self.quit) self.mainmenu.add_cascade(label="文件", menu=self.filemenu) self.master.config(menu=self.mainmenu)
def add_msg_frame(self,typeofmsg): # Destroy the existing Code Display Frame. if type(self.display_frame) is tkinter.Frame: self.display_frame.destroy() #++++++++++++++++++++++++ [New Code Display Section] ++++++++++++++++++++++++++++++++++++++++++++++ self.display_frame = tkinter.Frame(self.right) self.display_frame.pack(side='top',fill=BOTH,expand=1) self.canvas = tkinter.Canvas(self.display_frame) self.canvas.pack(side='left',fill=tkinter.BOTH,expand=1) self.scrollbar = ttk.Scrollbar(self.display_frame,orient=tkinter.VERTICAL,command=self.canvas.yview) self.scrollbar.pack(side='right',fill=tkinter.Y) self.canvas.configure(yscrollcommand=self.scrollbar.set) self.canvas.bind('<Configure>',lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all"))) self.sec_frame = tkinter.Frame(self.canvas) self.canvas.create_window((0,0),window=self.sec_frame,anchor='nw',width=385) # Set MIC Status. if typeofmsg == 1: self.htmlsnippet = ''' <div style="background-color:white;"> <h5 style="color: blue">I'm Listening...</h5> <p>speak after the sound</p> </div> ''' # HTML div to display MIC status. else: self.htmlsnippet = ''' <div style="background-color:white;"> <h5 style="color: red">Error</h5> <p>Didn't understand, Please try again</p> </div> ''' # HTML div to display Error Message. self.msg_display = HTMLLabel(self.sec_frame,html=self.htmlsnippet,height=6,background='white') # Display Status of Tool and MIC self.msg_display.pack()
class Window(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.master = master self.myfont = font.Font(family='Helvetica', size=14) self.init_window() def init_window(self): self.master.title("Markdown 编辑器") self.pack(fill=BOTH, expand=1) self.inputeditor = Text(self, width="1", font=self.myfont) self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT) self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Markdown 编辑器</h1>") self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT) self.outputbox.fit_height() self.inputeditor.bind("<<Modified>>", self.onInputChange) self.mainmenu = Menu(self) self.filemenu = Menu(self.mainmenu) self.filemenu.add_command(label="打开", command=self.openfile) self.filemenu.add_command(label="另存为", command=self.savefile) self.filemenu.add_separator() self.filemenu.add_command(label="退出", command=self.quit) self.mainmenu.add_cascade(label="文件", menu=self.filemenu) self.master.config(menu=self.mainmenu) def onInputChange(self, event): self.inputeditor.edit_modified(0) md2html = Markdown() self.outputbox.set_html(md2html.convert(self.inputeditor.get('1.0', END))) def openfile(self): openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *mdown , *.markdown"), ("Text File", "*.txt"), ("All Files", "*.*"))) if openfilename: try: self.inputeditor.delete(1.0, END) self.inputeditor.insert(END, open(openfilename, encoding='utf-8').read()) except Exception as e: mbox.showerror(f"无法打开文件({openfilename})!Error:{e}") def savefile(self): filedata = self.inputeditor.get("1.0", END) savefilename = filedialog.asksaveasfilename(filetypes=(("Markdown File", "*.md"), ("Text File", "*.txt")), title="保存Markdown 文件") if savefilename: try: with open(savefilename, 'w', encoding='utf-8') as f: f.write(filedata) except Exception as e: mbox.showerror("保存文件错误", f"文件{savefilename}保存错误!ERROR: {e}") def quit(self): self.master.quit()
class Window(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.master = master self.font = font.Font(family='Helvetica', size=14) self.init_window() def openfile(self): filename = \ filedialog.askopenfilename(filetypes=(('Markdown File', '*.md , *.mdown'), ('Text file', '*.txt'))) if filename: try: md2html = Markdown() self.outputbox.set_html(md2html.convert(open(filename, 'r').read())) except Exception: mbox.showerror('Error opening file', 'The selected file cannot be opened !') def init_window(self): self.master.title('Mardown Viewer') self.pack(fill=tk.BOTH, expand=1) self.mainmenu = tk.Menu(self) self.filemenu = tk.Menu(self.mainmenu) self.filemenu.add_command(label='Open', command=self.openfile) self.filemenu.add_separator() self.filemenu.add_command(label='Exit', command=self.quit) self.mainmenu.add_cascade(label='File', menu=self.filemenu) self.master.config(menu=self.mainmenu) self.outputbox = HTMLLabel(self, width='1', background='white', html='<h1>Welcome</h1>') self.outputbox.pack(fill=tk.BOTH, expand=1, side=tk.RIGHT) self.outputbox.fit_height()
def Results(): Button(root, text="Exit", command=Main) root.title('Results') root.geometry("1200x800") upper_frame = Frame( root, bg='#4c8a27', bd=5, ) upper_frame.place(relx=0.5, rely=0.1, relheight=0.2, relwidth=0.8, anchor="n") root_frame = Frame(root, bg='#4c8a27') lower_frame = Frame( root, bg='#4c8a27', bd=2, ) lower_frame.place(relx=0.5, rely=0.1, relheight=0.15, relwidth=1, anchor="n") create_back_button(root_frame) root_frame.place(relx=0.5, rely=0.0, relheight=1, relwidth=1, anchor='n') Label( root_frame, text= "Click on the link 'Click to view all results' to open up a Google sheets with all results", bg='#4c8a27', font="AutobusBold 12 bold").place(x=275, y=60) Label(root_frame, text="Click to view all results", bg='#add8e6', font="AutobusBold 15 bold").place(x=300, y=20, width=599) HTMLLabel( lower_frame, state="normal", fg='black', font="AutobusBold 30 bold", bg='#add8e6', html= '<a href="https://docs.google.com/spreadsheets/d/1cn8pl7UIQzIvn65ByVGZq8QswEd-FMTGybK50ab84pk/edit?usp=sharing"> Click to view the ' 'Results </a>').place(x=300, y=50, width=599) create_back_button(root) root.mainloop()
class MDText(Frame): def __init__(self, master, **kwargs): Frame.__init__(self, master, **kwargs) self.master = master self.myfont = font.Font(family="Helvetica", size=14) self.init_window() def init_window(self): self.pack(fill=BOTH, expand=1) self.inputeditor = Text(self, width="1", font=self.myfont, bg='black', insertbackground='white', fg='white', wrap=WORD) self.inputeditor.pack(fill=BOTH, expand=1, side=LEFT) self.outputbox = HTMLLabel(self, width="1", background="white", html="<h1>Welcome</h1>") self.outputbox.pack(fill=BOTH, expand=1, side=RIGHT) self.outputbox.fit_height() self.inputeditor.bind("<<Modified>>", self.onInputChange) self.mainmenu = Menu(self.master.master) self.filemenu = Menu(self.mainmenu) self.filemenu.add_command(label="Open", command=self.openfile) self.filemenu.add_command(label="Save as", command=self.savefile) self.filemenu.add_separator() self.filemenu.add_command(label="Exit", command=self.quit) self.mainmenu.add_cascade(label="File", menu=self.filemenu) self.master.master.config(menu=self.mainmenu) def onInputChange(self, event): self.inputeditor.edit_modified(0) md2html = Markdown() # self.outputbox.set_html(md2html.convert(self.inputeditor.get("1.0" , END))) markdownText = self.inputeditor.get("1.0", END) html = md2html.convert(markdownText) self.outputbox.set_html(html) def openfile(self): openfilename = filedialog.askopenfilename(filetypes=(("Markdown File", "*.md , *.mdown , *.markdown"), ("Text File", "*.txt"), ("All Files", "*.*"))) if openfilename: try: self.inputeditor.delete(1.0, END) self.inputeditor.insert(END, open(openfilename).read()) except: # print("Cannot Open File!") mbox.showerror("Error Opening Selected File" , "Oops!, The file you selected : {} can not be opened!".format(openfilename)) def savefile(self): filedata = self.inputeditor.get("1.0" , END) savefilename = filedialog.asksaveasfilename(filetypes = (("Markdown File", "*.md"), ("Text File", "*.txt")), title="Save Markdown File") if savefilename: try: f = open(savefilename, "w") f.write(filedata) except: mbox.showerror("Error Saving File", "Oops!, The File : {} can not be saved!".format(savefilename))
def get_md_preview_frame(master, html_var: StringVar): md_prev_frame = HTMLLabel(master, width='1', height='1', background=color['shell-dark'], padx=16, pady=16) def on_html_change(*_): # todo: find if there is any simpler way to change font color html_text = '<div style=\"color:' + color[ 'high'] + ';\">' + html_var.get() + '</div>' md_prev_frame.set_html(html_text) on_html_change() html_var.trace_add('write', on_html_change) return md_prev_frame
def google_search(self): try: from googlesearch import search except ImportError: print("An error when importing googlesearch has occurred.") return query = self.google_entry_str.get() self.result_screen.deiconify() self.result_screen.geometry("700x500") Label(self.result_screen, text="A list of URL's compiled by google.").pack() Label(self.result_screen, text="Keyword Searched: " + query).pack() for j in search(query, tld="co.in", num=5, stop=5): temp_label = HTMLLabel(self.result_screen, html='<a href="' + j + '">' + j + '</a>', fg="blue") temp_label.config(height=5) temp_label.pack()
def main_func(): global start, lbl3, country, textExample, countryCode_button, html_label lbl2.destroy() countries.destroy() lbl3 = Label( root, text="-------------" "-- ---------------" "--\n 'The future is ours to shape.\n I feel we" "are in a race that we need to win.\n It’s a race between the growing" " power\nof the technology and the growing\n wisdom" " we need to manage it.'\n " " ~Max Tegmark" " \n--------------- " " -----------------", bg="black", fg="white", font="Times 18", pady=10) lbl3.config(anchor=CENTER) lbl3.pack(pady=10) start.destroy() country = Label(root, text='Enter the country code to setup the alerts', bg="black", fg="white", font="Times 18", pady=10) country.pack(side=TOP, pady=10) textExample = Text(root, height=1, width=12) textExample.pack(side=TOP, pady=5) countryCode_button = Button(root, text="Enter", command=retrieve_input) countryCode_button.pack(side=TOP, pady=10) html_label = HTMLLabel(root, html='<a href="https://blockchain.info/ticker"' 'style="color: green; text-align: center"> ' ' Please visit:- https://blockchain.info/ticker, ' ' to know all the listed countries </a>') # html_label.pack(fill="both", expand=True) html_label.pack() html_label.fit_height()
from tkinter import * from tkhtmlview import HTMLLabel root = Tk() root.title('Codemy.com - Using HTML') root.iconbitmap('c:/gui/codemy.ico') root.geometry("500x600") my_label = HTMLLabel(root, html="\ <code><h1>\ <a href='https://codemy.com'>Learn To Code!</a>\ </h1></code>\ <ul>\ <li>One</li>\ <li>Two</li>\ <li>Three</li>\ </ul>\ <img src='c:/gui/images/aspen.png'>") my_label.pack(pady=20, padx=20, fill="both", expand=True) root.mainloop()
from tkinter import * from tkhtmlview import HTMLLabel root = Tk() root.title("Python Tkinter How To Use HTML In Your Tkinter App") root.geometry("500x600") my_label = HTMLLabel(root, html="\ <h1>\ <a href='https://www.python.org/'>Download Python</a>\ </h1>\ <ul>\ <li>One </li>\ <li>Two </li>\ <li>three </li>\ </ul>\ <img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTr9vl91PpaNrX7_EiOaWpTyftYzOFEiQixBA&usqp=CAU'> " ) my_label.pack(pady=20, padx=20, fill="both", expand=True) root.mainloop()
cv2.imshow("preview", frame) # if Answer==tkvar: # cv2.putText(frame, "Worked well", (x, y), cv2.FONT_HERSHEY_SIMPLEX, # 0.5, color, 2) # else: # cv2.putText(frame, "Try again", (x, y), cv2.FONT_HERSHEY_SIMPLEX, # 0.5, color, 2) camera.release() cv2.destroyAllWindows() #print(Answer) #w = Label(root, text="You can contribute at").grid(row = 4, column = 0) #t=HTMLLabel(root, html='<a href="https://childrenwithhearingloss.org/"> NGO </a>',font=("Courier", 1)).grid(row=5,column=0) w = Label(root, text="Learn Sign Language").grid(row=4, column=0) t = HTMLLabel( root, html='<a href="https://www.youtube.com/watch?v=Raa0vBXA8OQ"> Tutorial </a>', font=("Courier", 1)).grid(row=5, column=0) B = Button(root, text="Practice", command=press, font=("Times New Roman", 30)).grid(row=3, column=0) w = Label(root, text="ASL Practice Arena", font=("Times New Roman", 20)).grid(row=1, column=0) #tkvar.trace('w', change_dropdown) root.mainloop()
root.title('uing HTML') root.iconbitmap('ergo64.ico') root.geometry('500x600') # my_label = HTMLLabel (root, html="<a href='https://codemy.com'> LEARN TO CODE </a>") my_label = HTMLLabel(root, html="\ <h1>\ <a href='https://codemy.com'> LEARN TO CODE </a>\ </h1>\ <ol>\ <li>One</li>\ <li>Two</li>\ <li>Three</li>\ <li>Four</li>\ </ol>\ <ul>\ <li><h4>One</h4></li>\ <li><h5>Two</h5></li>\ <li>Three</li>\ <li>Four</li>\ </ul>\ <img src='https://cdn.codemy.com/wp-content/uploads/2015/01/sp21212.png'>\ <img src = 'C:/Users/eric/Pictures/mando2.png'>\ <pre><h1>\ <a href='https://codemy.com'> LEARN TO CODE </a>\ </h1></pre>\ ") my_label.pack(pady=20, padx=20, fill="both", expand=True) root.mainloop()
return html htmlChatConsoleWindow = tk.Frame(notebookTab3, width=335, height=150) htmlChatConsoleWindow.pack(fill="both", side="left", expand=True) htmlWindow = tk.Frame(htmlChatConsoleWindow, width=335, height=150) htmlWindow.pack(fill=BOTH, expand=1) htmlWindow.myfont = font.Font(family="Helvetica", size=14) htmlWindow.pack(fill=BOTH, expand=1) htmlWindow.inputeditor = Text(htmlWindow, width="1", height="0.25", font=htmlWindow.myfont) htmlWindow.inputeditor.pack(fill=X, expand=1, side=BOTTOM) htmlWindow.outputbox = HTMLLabel(htmlWindow, width="1", background="gray", html="<h1>Welcome</h1>") htmlWindow.outputbox.pack(fill="both", expand=1, side=TOP) htmlWindow.outputbox.fit_height() htmlWindow.inputeditor.bind("<Return>", onInputChange) # ______________________________________________________________ # | "Buttons" | Contains all the buttons that the user has added | # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ #Scrollbar useCommandsScrollbar = ttk.Scrollbar(useCommandsFrame, orient="vertical") useCommandsScrollbar.grid(column=1, row=0) #Command Buttons savedCommands = get_commands(SAVE_FILE_NAME) for commandTuple in savedCommands:
def search(self, keyword, endpoint, param1, param2): global entry global olist global res if endpoint == None: c.execute(f'SELECT * FROM {param1} LIMIT {param2}') data = c.fetchall() print(data) f = Frame(self.master) f.place(x=50, y=250, width=300) scroll_bar = Scrollbar(f) scroll_bar.pack(side=RIGHT, fill=Y) olist = Listbox(f, yscrollcommand=scroll_bar.set) olist.pack(fill=BOTH) scroll_bar.config(command=olist.yview) for i in range(len(data)): olist.insert(i, data[i][2]) else: searchtext = entry.get() print(searchtext) # Step 1 - Authorization url = "https://accounts.spotify.com/api/token" headers = {} data = {} # Encode as Base64 clientId = "<Enter your client Id>" clientSecret = "<Enter your Client Secret>" message = f"{clientId}:{clientSecret}" messageBytes = message.encode('ascii') base64Bytes = base64.b64encode(messageBytes) base64Message = base64Bytes.decode('ascii') headers['Authorization'] = f"Basic {base64Message}" data['grant_type'] = "client_credentials" r = requests.post(url, headers=headers, data=data) token = r.json()['access_token'] #print(token) token = r.json()['access_token'] # Step 2 - Use Access Token to call playlist endpoint print(keyword) print(searchtext) from googlesearch import search query = "spotify" + keyword + searchtext for i in search(query, num=1, stop=1): print(i) spotifyId = i.split("/")[-1] print(spotifyId) #playlistId = "7nYJDIm5nHyNTS2KugaD4w" if endpoint == "https://api.spotify.com/v1/artists": spotifyUrl = f"{endpoint}/{spotifyId}/top-tracks?market=ES" else: spotifyUrl = f"{endpoint}/{spotifyId}" print(spotifyUrl) headers = {"Authorization": "Bearer " + token} res = requests.get(url=spotifyUrl, headers=headers) f = Frame(self.master) f.place(x=50, y=250, width=300) scroll_bar = Scrollbar(f) scroll_bar.pack(side=RIGHT, fill=Y) olist = Listbox(f, yscrollcommand=scroll_bar.set) olist.pack(fill=BOTH) scroll_bar.config(command=olist.yview) print(res.json()) if endpoint == "https://api.spotify.com/v1/artists": for i in res.json()["tracks"]: olist.insert(END, i[param1][param2]) c.execute( 'INSERT INTO artisearch(id,Artist_Searched,Songs) VALUES(?,?,?)', (self.counter, searchtext, i[param1][param2])) self.counter += 1 con.commit() elif endpoint == "https://api.spotify.com/v1/tracks": for i in (res.json()["artists"]): olist.insert(END, i[param1][param2]) webbrowser.open(i[param1][param2]) c.execute( 'INSERT INTO songisearch(id,Song_Searched,Url) VALUES(?,?,?)', (self.counter, searchtext, i[param1][param2])) self.counter += 1 con.commit() else: for i in range(len(res.json()["tracks"]['items'])): olist.insert( END, res.json()["tracks"]['items'][i][param1][param2]) c.execute( 'INSERT INTO playlisearch(id,Playlist_Searched,Songs) VALUES(?,?,?)', (self.counter, searchtext, res.json()["tracks"]['items'][i][param1][param2])) self.counter += 1 con.commit() my_label = HTMLLabel(self.master, html=f""" <a style = "text-align : center;" href ="https://open.spotify.com/embed/{keyword}/{spotifyId}" width="50%" height="10" frameborder="0" allowtransparency="true" allow="encrypted-media">LISTEN NOW</a> """) # Adjust label my_label.place(x=400, y=250, width=100, height=27)
import tkinter as tk from tkhtmlview import HTMLLabel root = tk.Tk() html_label = HTMLLabel( root, html='<a href="http://www.google.com"> Google Hyperlink </a>') html_label.pack() root.mainloop()
import tkinter as tk from tkhtmlview import HTMLLabel win = tk.Tk() win.title("Link in Tkinter") instagram = HTMLLabel(win, html='<a href ="www.instagram.com"> Instagram </a>') google = HTMLLabel(win, html='<a href = "www.google.co.in"> Google </a>') whatsapp = HTMLLabel(win, html='<a href ="web.whatsapp.com"> Whatsapp </a>') News = HTMLLabel( win, html= '<a href ="news.google.com/topstories?hl=en-IN&gl=IN&ceid=IN:en"> News </a>' ) instagram.grid(row=0, column=0) google.grid(row=0, column=1) whatsapp.grid(row=0, column=2) News.grid(row=1, column=0) win.mainloop()
Éditeur : Laurent REYNAUD Date : 11-02-2021 """ # module qui requiert les packages # requests et Pillow pour les liens HTML from tkhtmlview import HTMLLabel import tkinter root = tkinter.Tk() root.iconbitmap('images/Logo.ico') root.title('Titre !') root.geometry('600x650') """Configuration d'une étiquette en HTML qui comprend : -> le lien @ du cours à partir d'une certaine séquence ; -> téléchargement de l'image du site codemy.com (clique droit puis copier l'adresse de l'image) ; -> une liste ordonnée """ my_label = HTMLLabel( root, html= "<h1><pre><a href=https://youtu.be/d6UitRCstiQ?t=377>Coder avec HTML</a></pre></h1>" # lien @ "<img src=https://cdn.codemy.com/wp-content/uploads/2015/01/sp21212.png>" # image téléchargée "<ol><li>Un</li><li>Deux</li><li>Trois</li><li>Houlala !!!</li></ol>" # liste ordonnée ) my_label.pack(pady=20, padx=20, fill="both", expand=True) root.mainloop()
Button(quickmenu, text="斜体", command=unc, width=6, height=3).place(x=300, y=50) Button(quickmenu, text="引用", command=userfrom, width=6, height=3).place(x=360, y=50) Button(quickmenu, text="图片", command=pic, width=6, height=3).place(x=420, y=50) Button(quickmenu, text="超链接", command=superlink, width=6, height=3).place(x=480, y=50) tools.place(x=0, y=0) def onInputChange(event): inputeditor.edit_modified(0) md2html = Markdown() outputbox.set_html(md2html.convert(inputeditor.get("1.0", END))) inputeditor = Text(showbar, height=70, width=60) #inputeditor.pack(fill=BOTH, expand=1, side=LEFT) inputeditor.pack(side=LEFT, fill=BOTH) outputbox = HTMLLabel(showbar, background="white", html="<h1>这里什么也没有写</h1>", height=600, width=55) outputbox.pack(side=RIGHT, fill=BOTH) inputeditor.bind("<<Modified>>", onInputChange) #outputbox.pack(fill=BOTH, expand=1, side=RIGHT) outputbox.fit_height() #Button(showbar).place(x=0,y=0)\ root.mainloop()
markdown = Markdown() markdownText = markdown_editor.get("1.0", END) html = markdown.convert(markdownText) result.set_html(html) # Creating tkinter window window = Tk() window.title('Markdown viewer') window.geometry('1200x1000') window.configure(bg='white') # Styling font and button myfont = font.Font(family="Helvetica", size=14) style = Style() style.configure('TButton', font=('calibri', 20, 'bold'), foreground='Blue') # Placing widgets into Tkinter window submit_btn = Button(text="View Markdown", command=onKeyUp, style='TButton') submit_btn.pack(ipadx=30, ipady=6) markdown_editor = Text(width="1", insertborderwidth=2, selectborderwidth=2) markdown_editor.insert(END, '# Add Markdown here') markdown_editor.pack(fill=BOTH, expand=1, side=LEFT, padx=10, pady=10) markdown_editor.configure(font=myfont) result = HTMLLabel(width="1", html="<h1>Markdown Viewer</h1>") result.pack(fill=BOTH, expand=1, side=RIGHT, padx=10, pady=10) window.mainloop()
import tkinter as tk from tkhtmlview import HTMLLabel root = tk.Tk() root.title("Test Html on Tkinter") root.configure(bg='black') data = """<!-- Dynamic Coding output code --> <p style="border: 2px solid rgb(51, 103, 214); font-size: 15px; padding: 0.2em 0.6em;"><font face="arial"> <kbd style="border-radius: 0px; border: 1px solid rgb(51, 103, 214); padding: 3px;color:#3367d6;"><b> Output </b></kbd> <br /> <code style="color:#ff0000"> deque(['A', 'B', 'C', 'D']) </code> </font></p> <br /> """ html_label = HTMLLabel(root, html=data) html_label.pack(fill="both", expand=True) html_label.fit_height() root.mainloop()
import tkinter as tk from tkhtmlview import HTMLLabel root = tk.Tk() html_label = HTMLLabel( root, html='<h1 style="color: red; text-align: center"> Hello World </H1>') html_label.pack(fill="both", expand=True) html_label.fit_height() root.mainloop()