Advertisement
Jump_off_a_cliff

URL Opener GUI / / Made with Github Copilot

May 28th, 2022
746
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Import the necessary modules
  2. from tkinter import *
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5. import webbrowser
  6.  
  7.  
  8. # Create a class for the main window
  9. class MainWindow(Tk):
  10.     # Create a constructor for the main window
  11.  
  12.     def __init__(self):
  13.         # Call the constructor for the parent class
  14.         super().__init__()
  15.         # Set the title of the window
  16.         self.title("URL Opener")
  17.         # Set the size of the window
  18.         self.geometry("300x100")
  19.         # Create a label for the url
  20.         self.url_label = ttk.Label(self, text="URL:")
  21.         # Create a text box for the url
  22.         self.url_text = ttk.Entry(self)
  23.         # Create a button to open the url
  24.         self.open_button = ttk.Button(self, text="Open", command=self.open_url)
  25.         # Place the label and text box in the window
  26.         self.url_label.grid(row=0, column=0)
  27.         self.url_text.insert(index=0, string="https://www.google.com")
  28.         self.url_text.grid(row=0, column=1)
  29.         # Place the button in the window
  30.         self.open_button.grid(row=1, column=0, columnspan=2)
  31.  
  32.     # Create a function to open the url
  33.     def open_url(self):
  34.         # Get the url from the text box
  35.         url = self.url_text.get()
  36.         # Open the url in a new tab in the browser
  37.         webbrowser.open_new_tab(url)
  38.  
  39.     # Create a function to close the window
  40.     def close_window(self):
  41.         # Close the window
  42.         self.destroy()
  43.  
  44.     # Create a function to show a message box
  45.     def show_message(self, message):
  46.         # Show a message box with the message
  47.         messagebox.showinfo("Message", message)
  48.  
  49.     # Create a function to show an error message
  50.     def show_error(self, message):
  51.         # Show an error message with the message
  52.         messagebox.showerror("Error", message)
  53.  
  54.     # Create a function to show a warning message
  55.     def show_warning(self, message):
  56.         # Show a warning message with the message
  57.         messagebox.showwarning("Warning", message)
  58.  
  59.     # Create a function to show a question message
  60.     def show_question(self, message):
  61.         # Show a question message with the message
  62.         messagebox.askquestion("Question", message)
  63.  
  64.     # Create a function to show a yes/no question message
  65.     def show_yes_no(self, message):
  66.         # Show a yes/no question message with the message
  67.         messagebox.askyesno("Question", message)
  68.  
  69.     # Create a function to show a yes/no/cancel question message
  70.     def show_yes_no_cancel(self, message):
  71.         # Show a yes/no/cancel question message with the message
  72.         messagebox.askyesnocancel("Question", message)
  73.  
  74.     # Create a function to show a ok/cancel question message
  75.     def show_ok_cancel(self, message):
  76.         # Show a ok/cancel question message with the message
  77.         messagebox.askokcancel("Question", message)
  78.  
  79.     # Create a function to show a ok/cancel/help question message
  80.     def show_ok_cancel_help(self, message):
  81.         # Show a ok/cancel/help question message with the message
  82.         messagebox.askokcancel("Question", message)
  83.  
  84.     # Create a function to show a retry/cancel question message
  85.     def show_retry_cancel(self, message):
  86.         # Show a retry/cancel question message with the message
  87.         messagebox.askretrycancel("Question", message)
  88.  
  89.     # Create a function to show a open/cancel question message
  90.     def show_open_cancel(self, message):
  91.         # Show a open/cancel question message with the message
  92.         messagebox.askopenfilename("Question", message)
  93.  
  94.     # Create a function to show a save/cancel question message
  95.     def show_save_cancel(self, message):
  96.         # Show a save/cancel question message with the message
  97.         messagebox.asksaveasfilename("Question", message)
  98.  
  99.     # Create a function to show a open/save/cancel question message
  100.     def show_open_save_cancel(self, message):
  101.         # Show a open/save/cancel question message with the message
  102.         messagebox.asksaveasfilename("Question", message)
  103.  
  104.     # Create a function to show a open/save/cancel/help question message
  105.     def show_open_save_cancel_help(self, message):
  106.         # Show a open/save/cancel/help question message with the message
  107.         messagebox.asksaveasfilename("Question", message)
  108.  
  109.  
  110. # Create a function to run the program
  111. def run_program():
  112.     # Create a new main window
  113.     main_window = MainWindow()
  114.     # Run the main loop
  115.     main_window.mainloop()
  116.     # Return the main window
  117.     return main_window
  118.  
  119.  
  120. # Run the program
  121. run_program()
  122.  
  123.  
Advertisement
RAW Paste Data Copied
Advertisement