Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import the necessary modules
- from tkinter import *
- from tkinter import ttk
- from tkinter import messagebox
- import webbrowser
- # Create a class for the main window
- class MainWindow(Tk):
- # Create a constructor for the main window
- def __init__(self):
- # Call the constructor for the parent class
- super().__init__()
- # Set the title of the window
- self.title("URL Opener")
- # Set the size of the window
- self.geometry("300x100")
- # Create a label for the url
- self.url_label = ttk.Label(self, text="URL:")
- # Create a text box for the url
- self.url_text = ttk.Entry(self)
- # Create a button to open the url
- self.open_button = ttk.Button(self, text="Open", command=self.open_url)
- # Place the label and text box in the window
- self.url_label.grid(row=0, column=0)
- self.url_text.insert(index=0, string="https://www.google.com")
- self.url_text.grid(row=0, column=1)
- # Place the button in the window
- self.open_button.grid(row=1, column=0, columnspan=2)
- # Create a function to open the url
- def open_url(self):
- # Get the url from the text box
- url = self.url_text.get()
- # Open the url in a new tab in the browser
- webbrowser.open_new_tab(url)
- # Create a function to close the window
- def close_window(self):
- # Close the window
- self.destroy()
- # Create a function to show a message box
- def show_message(self, message):
- # Show a message box with the message
- messagebox.showinfo("Message", message)
- # Create a function to show an error message
- def show_error(self, message):
- # Show an error message with the message
- messagebox.showerror("Error", message)
- # Create a function to show a warning message
- def show_warning(self, message):
- # Show a warning message with the message
- messagebox.showwarning("Warning", message)
- # Create a function to show a question message
- def show_question(self, message):
- # Show a question message with the message
- messagebox.askquestion("Question", message)
- # Create a function to show a yes/no question message
- def show_yes_no(self, message):
- # Show a yes/no question message with the message
- messagebox.askyesno("Question", message)
- # Create a function to show a yes/no/cancel question message
- def show_yes_no_cancel(self, message):
- # Show a yes/no/cancel question message with the message
- messagebox.askyesnocancel("Question", message)
- # Create a function to show a ok/cancel question message
- def show_ok_cancel(self, message):
- # Show a ok/cancel question message with the message
- messagebox.askokcancel("Question", message)
- # Create a function to show a ok/cancel/help question message
- def show_ok_cancel_help(self, message):
- # Show a ok/cancel/help question message with the message
- messagebox.askokcancel("Question", message)
- # Create a function to show a retry/cancel question message
- def show_retry_cancel(self, message):
- # Show a retry/cancel question message with the message
- messagebox.askretrycancel("Question", message)
- # Create a function to show a open/cancel question message
- def show_open_cancel(self, message):
- # Show a open/cancel question message with the message
- messagebox.askopenfilename("Question", message)
- # Create a function to show a save/cancel question message
- def show_save_cancel(self, message):
- # Show a save/cancel question message with the message
- messagebox.asksaveasfilename("Question", message)
- # Create a function to show a open/save/cancel question message
- def show_open_save_cancel(self, message):
- # Show a open/save/cancel question message with the message
- messagebox.asksaveasfilename("Question", message)
- # Create a function to show a open/save/cancel/help question message
- def show_open_save_cancel_help(self, message):
- # Show a open/save/cancel/help question message with the message
- messagebox.asksaveasfilename("Question", message)
- # Create a function to run the program
- def run_program():
- # Create a new main window
- main_window = MainWindow()
- # Run the main loop
- main_window.mainloop()
- # Return the main window
- return main_window
- # Run the program
- run_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement