Advertisement
Guest User

py2exe

a guest
Jan 1st, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from tkinter import *
  4. import webbrowser as web
  5.  
  6. # Для упрощения ображения к приложению
  7. app = tk.Tk()
  8. app.title("Поисковая система")
  9. app.configure(background = "#fcfcfc")
  10.  
  11. # Стили: font - название, размер и толщина; foreground - цвет
  12. app_name = ttk.Label(app, text="Поисковое приложение", font = "Arial 16 bold", foreground = "#222")
  13. app_name.grid(row=0, column=1)
  14.  
  15. # Создание и позиционирование элементов (про грид узнать получше)
  16. search_label = ttk.Label(app, text="Поиск")
  17. search_label.grid(row=1, column=0)
  18.  
  19. #Текстовое поле
  20. text_field = ttk.Entry(app, width=50)
  21. text_field.grid(row=1,column=1)
  22.  
  23. #Переменная радиокнопки
  24. search_engine = StringVar()
  25. search_engine.set("google")
  26.  
  27. # Использование модуля webbrowser(web)
  28. def search():
  29.     if text_field.get().strip() !="":
  30.         if search_engine.get() == "google":
  31.             web.open("https://www.google.com/search?q=" + text_field.get())
  32.         elif search_engine.get() == "yandex":
  33.             web.open("https://yandex.ru/search/?text=" + text_field.get())
  34.  
  35. # Событие нажания на кнопку "Найти"
  36. def searchBtn():
  37.     search()
  38.  
  39. # Событие нажания на кноку Enter
  40. def enterBtn(event):
  41.     search()
  42.  
  43. # Command — функция, вызываемая при нажатии
  44. button_search = ttk.Button(app, text= "Найти", width=15, command=search)
  45. button_search.grid(row=1,column=2)
  46.  
  47. # В прямом смысле биндим Ентер к событию
  48. text_field.bind("<Return>", enterBtn)
  49.  
  50. # Радиокнопка Google
  51. radio_google = ttk.Radiobutton(app, text="Google", value = "google", variable = search_engine)
  52. radio_google.grid(row=2, column=1, sticky=W)
  53. # Радиокнопка Yandex
  54. radio_yandex = ttk.Radiobutton(app, text="Yandex", value = "yandex", variable = search_engine)
  55. radio_yandex.grid(row=2, column=1, sticky=E)
  56. # Изменение приоритета приложения. В данном случае оно всегда будет на виду
  57. app.wm_attributes('-topmost', True)
  58.  
  59. #Фокусировка при запуске
  60. text_field.focus()
  61. # Обязательная хуета, дабы приложение работало столько, сколько нужно
  62. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement