Advertisement
Najeebsk

PYTHON-ALL-CODE-EXAMPLES.py

Mar 22nd, 2024 (edited)
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 22.93 KB | None | 0 0
  1.         # Color Palette
  2.         self.bg_color = "#336699"
  3.         self.button_color = "#4CAF50"
  4.         self.text_color = "white"
  5. ----------------------------------------------
  6. self.title_label = tk.Label(self.main_frame, text="NAJEEB VIDEO PLAYER", font=("Arial", 24, "bold"), fg=self.text_color, bg=self.bg_color)
  7.         self.title_label.pack(pady=10)
  8. --------------------------------------------------------------------
  9. self.search_button = tk.Button(self.search_frame, text="Search YouTube", command=self.search_and_play, bg=self.button_color, fg=self.text_color)
  10.         self.search_button.pack(side="left", padx=5, pady=5)
  11.  
  12.         self.save_button = tk.Button(self.search_frame, text="Save", command=self.save_results, bg=self.button_color, fg=self.text_color)
  13.         self.save_button.pack(side="left", padx=5, pady=5)
  14. -----------------------------------------------------------------------------
  15. self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_page, bg=self.button_color, fg=self.text_color)
  16.         self.prev_button.pack(side="left", padx=5, pady=5)
  17.  
  18.         self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_page, bg=self.button_color, fg=self.text_color)
  19.         self.next_button.pack(side="left", padx=5, pady=5)
  20.  
  21.         self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video, bg=self.button_color, fg=self.text_color)
  22.         self.play_button.pack(side="left", padx=5, pady=5)
  23.  
  24.         self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video, bg=self.button_color, fg=self.text_color)
  25.         self.stop_button.pack(side="left", padx=5, pady=5)
  26.  
  27.         self.current_video_label = tk.Label(root, text="No video selected", bg=self.bg_color, fg=self.text_color)
  28.         self.current_video_label.pack(pady=5)
  29.  
  30.         self.time_label = tk.Label(root, text="", bg=self.bg_color, fg=self.text_color)
  31.         self.time_label.pack(pady=5)
  32.  
  33.         self.slider = tk.Scale(root, from_=0, to=100, orient="horizontal", bg=self.bg_color, fg=self.text_color, command=self.set_video_position)
  34.         self.slider.pack(fill="x")
  35. ------------------------------------------------------------------------
  36. root = tk.Tk()
  37. root.geometry("800x600+300+50")
  38. root.title("Najeeb VLC Player")
  39. root.configure(bg="#336699")
  40. video_player = VideoPlayer(root)
  41. root.mainloop()
  42. --------------------------------------------------
  43. # Create the main application window
  44. app = tk.Tk()
  45. app.title("Najeeb IPTV Channel Search M3u All Category")
  46. app.geometry("800x600")
  47. app.configure(bg="#336699")
  48. -------------------------------------------------------------------------------
  49. # Add labels, entry fields, buttons, etc.
  50. url_frame = tk.Frame(app, bg="#336699")
  51. url_frame.pack(pady=10)
  52.  
  53. url_label = tk.Label(url_frame, text="Enter URL 0R local OR Select Category:", bg="#336699", fg="white")
  54. url_label.pack(side=tk.LEFT, padx=5)
  55.  
  56. url_entry = tk.Entry(url_frame, width=80)  # Adjust width here
  57. url_entry.pack(side=tk.LEFT, padx=5)
  58.  
  59. search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
  60. search_button.pack(side=tk.LEFT, padx=5)
  61.  
  62. result_label = tk.Label(app, text="Najeeb Iptv Channels Run Vlc Player Check Working Or Not Working And save Working URLS in M3U File:", bg="#336699", fg="white")
  63. result_label.pack()
  64.  
  65. # Add scrollbar to the listbox
  66. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  67. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  68.  
  69. result_text = tk.Listbox(app, height=30, width=130, yscrollcommand=scrollbar.set)
  70. result_text.pack()
  71.  
  72. # Configure scrollbar
  73. scrollbar.config(command=result_text.yview)
  74.  
  75. # Bind double click event to play_selected_channel function
  76. result_text.bind("<Double-1>", play_selected_channel)
  77.  
  78. # Add button to check links
  79. check_button = tk.Button(app, text="Check Links", command=check_links, bg="#008000", fg="white")
  80. check_button.pack(side=tk.RIGHT, padx=5)
  81.  
  82. # Add button to save working links
  83. save_button = tk.Button(app, text="Save Working Links", command=save_working_links, bg="#FF0000", fg="white")
  84. save_button.pack(side=tk.LEFT, padx=5)
  85.  
  86. # Dropdown menu for channel categories
  87. category_urls = {
  88.     "ALL-CATEGORY": "",
  89.     "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
  90.     "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
  91.     "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
  92.     "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
  93.     "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
  94.     "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
  95.     "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
  96.     "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
  97.     "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
  98.     "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
  99.     "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
  100.     "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
  101.     "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
  102.     "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
  103.     "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
  104.     "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
  105.     "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
  106.     "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
  107.     "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
  108.     "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
  109.     "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
  110.     "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
  111.     "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
  112.     "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
  113.     "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
  114.     "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
  115.     "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
  116.     "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
  117.     "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u",
  118.     # Add more categories here
  119. }
  120. ========================= START===========================
  121. import tkinter as tk
  122. window = tk.Tk()
  123. greeting = tk.Label(text="Hello, Tkinter")
  124. greeting.pack()
  125. label = tk.Label(text="Hello, Tkinter")
  126. label = tk.Label(
  127.     text="Hello, Tkinter",
  128.     foreground="white",  # Set the text color to white
  129.     background="black"  # Set the background color to black
  130. )
  131.     "red"
  132.     "orange"
  133.     "yellow"
  134.     "green"
  135.     "blue"
  136.     "purple"
  137. label = tk.Label(text="Hello, Tkinter", background="#34A2FE")
  138. label = tk.Label(text="Hello, Tkinter", fg="white", bg="black")
  139. label = tk.Label(
  140.     text="Hello, Tkinter",
  141.     fg="white",
  142.     bg="black",
  143.     width=10,
  144.     height=10
  145. )
  146. button = tk.Button(
  147.     text="Click me!",
  148.     width=25,
  149.     height=5,
  150.     bg="blue",
  151.     fg="yellow",
  152. )
  153. entry = tk.Entry(fg="yellow", bg="blue", width=50)
  154. import tkinter as tk
  155. window = tk.Tk()
  156. label = tk.Label(text="Name")
  157. entry = tk.Entry()
  158. label.pack()
  159. entry.pack()
  160. name = entry.get()
  161.  
  162. name
  163.  
  164. 'Real Python'
  165. entry.delete(0)
  166. entry.delete(0, tk.END)
  167. entry.insert(0, "Python")
  168. entry.insert(0, "Real ")
  169. window.destroy()
  170. window = tk.Tk()
  171. text_box = tk.Text()
  172. text_box.pack()
  173. text_box.get()
  174. Traceback (most recent call last):
  175.   ...
  176. TypeError: get() missing 1 required positional argument: 'index1'
  177. text_box.get("1.0")
  178. text_box.get("1.0", "1.5")
  179. 'Hello'
  180. text_box.get("2.0", "2.5")
  181. 'World'
  182. text_box.get("1.0", tk.END)
  183. 'Hello\nWorld\n'
  184. text_box.delete("1.0", "1.4")
  185. text_box.get("1.0")
  186. '\n'
  187. text_box.delete("1.0")
  188. text_box.delete("1.0", tk.END)
  189. text_box.insert("1.0", "Hello")
  190. text_box.insert("2.0", "World")
  191. text_box.insert("2.0", "\nWorld")
  192. text_box.insert(tk.END, "Put me at the end!")
  193. text_box.insert(tk.END, "\nPut me on a new line!")
  194. -----------------------------------------------------------------------
  195. Assigning Widgets to Frames With Frame Widgets
  196. In this tutorial, you’re going to work with only five widgets:
  197.  1   Label
  198.  2   Button
  199.  3   Entry
  200.  4   Text
  201.  5   Frame
  202. These are the four you’ve seen so far plus the Frame widget.
  203. Frame widgets are important for organizing the layout of your widgets in an application.
  204. --------------------------------------------------------------------------
  205. import tkinter as tk
  206.  
  207. window = tk.Tk()
  208. frame = tk.Frame()
  209. frame.pack()
  210.  
  211. window.mainloop()
  212. -------------------------------------
  213. frame = tk.Frame()
  214. label = tk.Label(master=frame)
  215. ----------------------------------------
  216. import tkinter as tk
  217.  
  218. window = tk.Tk()
  219.  
  220. frame_a = tk.Frame()
  221. frame_b = tk.Frame()
  222.  
  223. label_a = tk.Label(master=frame_a, text="I'm in Frame A")
  224. label_a.pack()
  225.  
  226. label_b = tk.Label(master=frame_b, text="I'm in Frame B")
  227. label_b.pack()
  228.  
  229. frame_a.pack()
  230. frame_b.pack()
  231.  
  232. window.mainloop()
  233. --------------------------------------
  234. import tkinter as tk
  235.  
  236. window = tk.Tk()
  237.  
  238. frame_a = tk.Frame()
  239. label_a = tk.Label(master=frame_a, text="I'm in Frame A")
  240. label_a.pack()
  241.  
  242. frame_b = tk.Frame()
  243. label_b = tk.Label(master=frame_b, text="I'm in Frame B")
  244. label_b.pack()
  245.  
  246. # Swap the order of `frame_a` and `frame_b`
  247. frame_b.pack()
  248. frame_a.pack()
  249.  
  250. window.mainloop()
  251. ---------------------------------------
  252. Adjusting Frame Appearance With Reliefs
  253. Frame widgets can be configured with a relief attribute that creates a border around the frame.
  254.  You can set relief to be any of the following values:
  255. 1    tk.FLAT: Has no border effect (the default value)
  256. 2    tk.SUNKEN: Creates a sunken effect
  257. 3    tk.RAISED: Creates a raised effect
  258. 4    tk.GROOVE: Creates a grooved border effect
  259. 5    tk.RIDGE: Creates a ridged effect
  260. To apply the border effect, you must set the borderwidth attribute to a value
  261. ------------------------------------------------------------------------------------
  262. import tkinter as tk
  263.  
  264.  
  265. border_effects = {
  266.  
  267.     "flat": tk.FLAT,
  268.  
  269.     "sunken": tk.SUNKEN,
  270.  
  271.     "raised": tk.RAISED,
  272.  
  273.     "groove": tk.GROOVE,
  274.  
  275.     "ridge": tk.RIDGE,
  276.  
  277. }
  278.  
  279.  
  280. window = tk.Tk()
  281.  
  282.  
  283. for relief_name, relief in border_effects.items():
  284.  
  285.     frame = tk.Frame(master=window, relief=relief, borderwidth=5)
  286.  
  287.     frame.pack(side=tk.LEFT)
  288.  
  289.     label = tk.Label(master=frame, text=relief_name)
  290.  
  291.     label.pack()
  292.  
  293.  
  294. window.mainloop()
  295. --------------------------------------
  296.  tk.Label(text="Hello, Tkinter").pack()
  297. --------------------------------------------------
  298. Widget Class    Variable Name Prefix    Example
  299. Label                           lbl                                           lbl_name
  300. Button                          btn                                           btn_submit
  301. Entry                           ent                                           ent_age
  302. Text                            txt                                           txt_notes
  303. Frame                           frm                                           frm_address
  304. ----------------------------------------------------------------------------------------
  305. 1    .place()
  306. 2    .grid()
  307. -----------------------------
  308. The .pack() Geometry Manager
  309. -----------------------------
  310. import tkinter as tk
  311.  
  312. window = tk.Tk()
  313.  
  314. frame1 = tk.Frame(master=window, width=100, height=100, bg="red")
  315. frame1.pack()
  316.  
  317. frame2 = tk.Frame(master=window, width=50, height=50, bg="yellow")
  318. frame2.pack()
  319.  
  320. frame3 = tk.Frame(master=window, width=25, height=25, bg="blue")
  321. frame3.pack()
  322.  
  323. window.mainloop()
  324. --------------------------------------------------------------------
  325. import tkinter as tk
  326.  
  327. window = tk.Tk()
  328.  
  329. frame1 = tk.Frame(master=window, height=100, bg="red")
  330. frame1.pack(fill=tk.X)
  331.  
  332. frame2 = tk.Frame(master=window, height=50, bg="yellow")
  333. frame2.pack(fill=tk.X)
  334.  
  335. frame3 = tk.Frame(master=window, height=25, bg="blue")
  336. frame3.pack(fill=tk.X)
  337.  
  338. window.mainloop()
  339. -----------------------------------------------------------------------
  340. 1    tk.TOP
  341. 2    tk.BOTTOM
  342. 3    tk.LEFT
  343. 4    tk.RIGHT
  344. -------------------------------------------
  345. import tkinter as tk
  346.  
  347. window = tk.Tk()
  348.  
  349. frame1 = tk.Frame(master=window, width=200, height=100, bg="red")
  350. frame1.pack(fill=tk.Y, side=tk.LEFT)
  351.  
  352. frame2 = tk.Frame(master=window, width=100, bg="yellow")
  353. frame2.pack(fill=tk.Y, side=tk.LEFT)
  354.  
  355. frame3 = tk.Frame(master=window, width=50, bg="blue")
  356. frame3.pack(fill=tk.Y, side=tk.LEFT)
  357.  
  358. window.mainloop()
  359. ------------------------------------------
  360. import tkinter as tk
  361.  
  362. window = tk.Tk()
  363.  
  364. frame1 = tk.Frame(master=window, width=200, height=100, bg="red")
  365. frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  366.  
  367. frame2 = tk.Frame(master=window, width=100, bg="yellow")
  368. frame2.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  369.  
  370. frame3 = tk.Frame(master=window, width=50, bg="blue")
  371. frame3.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  372.  
  373. window.mainloop()
  374. ----------------------------------------------------------------------------
  375. The .place() Geometry Manager
  376. -------------------------------------
  377. import tkinter as tk
  378.  
  379.  
  380. window = tk.Tk()
  381.  
  382.  
  383. frame = tk.Frame(master=window, width=150, height=150)
  384.  
  385. frame.pack()
  386.  
  387.  
  388. label1 = tk.Label(master=frame, text="I'm at (0, 0)", bg="red")
  389.  
  390. label1.place(x=0, y=0)
  391.  
  392.  
  393. label2 = tk.Label(master=frame, text="I'm at (75, 75)", bg="yellow")
  394.  
  395. label2.place(x=75, y=75)
  396.  
  397.  
  398. window.mainloop()
  399. ---------------------------------------------------------------
  400. The .grid() Geometry Manager
  401. ---------------------------------------
  402. import tkinter as tk
  403.  
  404. window = tk.Tk()
  405.  
  406. for i in range(3):
  407.     for j in range(3):
  408.         frame = tk.Frame(
  409.             master=window,
  410.             relief=tk.RAISED,
  411.             borderwidth=1
  412.         )
  413.         frame.grid(row=i, column=j)
  414.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  415.         label.pack()
  416.  
  417. window.mainloop()
  418. -------------------------------------------------------------------
  419. import tkinter as tk
  420.  
  421. window = tk.Tk()
  422.  
  423. for i in range(3):
  424.     for j in range(3):
  425.         frame = tk.Frame(
  426.             master=window,
  427.             relief=tk.RAISED,
  428.             borderwidth=1
  429.         )
  430.         frame.grid(row=i, column=j)
  431.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  432.         label.pack()
  433.  
  434. window.mainloop()
  435. ------------------------------------------------------------------------
  436. import tkinter as tk
  437.  
  438. window = tk.Tk()
  439.  
  440. for i in range(3):
  441.     for j in range(3):
  442.         frame = tk.Frame(
  443.             master=window,
  444.             relief=tk.RAISED,
  445.             borderwidth=1
  446.         )
  447.         frame.grid(row=i, column=j)
  448.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  449.         label.pack()
  450.  
  451. window.mainloop()
  452. -------------------------------------------------------------------------
  453. 1    padx adds padding in the horizontal direction.
  454. 2    pady adds padding in the vertical direction.
  455. -----------------------------------------------------------------
  456. import tkinter as tk
  457.  
  458. window = tk.Tk()
  459.  
  460. for i in range(3):
  461.     for j in range(3):
  462.         frame = tk.Frame(
  463.             master=window,
  464.             relief=tk.RAISED,
  465.             borderwidth=1
  466.         )
  467.         frame.grid(row=i, column=j, padx=5, pady=5)
  468.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  469.         label.pack()
  470.  
  471. window.mainloop()
  472. ------------------------------------------------------------------------
  473. import tkinter as tk
  474.  
  475. window = tk.Tk()
  476.  
  477. for i in range(3):
  478.     for j in range(3):
  479.         frame = tk.Frame(
  480.             master=window,
  481.             relief=tk.RAISED,
  482.             borderwidth=1
  483.         )
  484.         frame.grid(row=i, column=j, padx=5, pady=5)
  485.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  486.         label.pack(padx=5, pady=5)
  487.  
  488. window.mainloop()
  489. ----------------------------------------------------------------------------
  490. 1    Index: The index of the grid column or row that you want to configure or a list
  491.       of indices to configure multiple rows or columns at the same time
  492. 2    Weight: A keyword argument called weight that determines how the column or row
  493.       should respond to window resizing, relative to the other columns and rows
  494. 3    Minimum Size: A keyword argument called minsize that sets the minimum size
  495.       of the row height or column width in pixels
  496. ------------------------------------------------------------------------------------------------
  497. import tkinter as tk
  498.  
  499. window = tk.Tk()
  500.  
  501. for i in range(3):
  502.     window.columnconfigure(i, weight=1, minsize=75)
  503.     window.rowconfigure(i, weight=1, minsize=50)
  504.  
  505.     for j in range(0, 3):
  506.         frame = tk.Frame(
  507.             master=window,
  508.             relief=tk.RAISED,
  509.             borderwidth=1
  510.         )
  511.         frame.grid(row=i, column=j, padx=5, pady=5)
  512.         label = tk.Label(master=frame, text=f"Row {i}\nColumn {j}")
  513.         label.pack(padx=5, pady=5)
  514.  
  515. window.mainloop()
  516. --------------------------------------------------------------------------------------------------
  517. import tkinter as tk
  518.  
  519. window = tk.Tk()
  520. window.columnconfigure(0, minsize=250)
  521. window.rowconfigure([0, 1], minsize=100)
  522.  
  523. label1 = tk.Label(text="A")
  524. label1.grid(row=0, column=0)
  525.  
  526. label2 = tk.Label(text="B")
  527. label2.grid(row=1, column=0)
  528.  
  529. window.mainloop()
  530. -----------------------------------------------------------------------------------------------------
  531. 1    "n" or "N" to align to the top-center part of the cell
  532. 2    "e" or "E" to align to the right-center side of the cell
  533. 3    "s" or "S" to align to the bottom-center part of the cell
  534. 4    "w" or "W" to align to the left-center side of the cell
  535. -----------------------------------------------------------------------------------
  536. import tkinter as tk
  537.  
  538. window = tk.Tk()
  539. window.columnconfigure(0, minsize=250)
  540. window.rowconfigure([0, 1], minsize=100)
  541.  
  542. label1 = tk.Label(text="A")
  543. label1.grid(row=0, column=0, sticky="n")
  544.  
  545. label2 = tk.Label(text="B")
  546. label2.grid(row=1, column=0, sticky="n")
  547.  
  548. window.mainloop()
  549. ------------------------------------------------------------------------------------
  550. import tkinter as tk
  551.  
  552. window = tk.Tk()
  553. window.columnconfigure(0, minsize=250)
  554. window.rowconfigure([0, 1], minsize=100)
  555.  
  556. label1 = tk.Label(text="A")
  557. label1.grid(row=0, column=0, sticky="ne")
  558.  
  559. label2 = tk.Label(text="B")
  560. label2.grid(row=1, column=0, sticky="sw")
  561.  
  562. window.mainloop()
  563. -------------------------------------------------------------------------------------
  564. import tkinter as tk
  565.  
  566. window = tk.Tk()
  567.  
  568. window.rowconfigure(0, minsize=50)
  569. window.columnconfigure([0, 1, 2, 3], minsize=50)
  570.  
  571. label1 = tk.Label(text="1", bg="black", fg="white")
  572. label2 = tk.Label(text="2", bg="black", fg="white")
  573. label3 = tk.Label(text="3", bg="black", fg="white")
  574. label4 = tk.Label(text="4", bg="black", fg="white")
  575.  
  576. label1.grid(row=0, column=0)
  577. label2.grid(row=0, column=1, sticky="ew")
  578. label3.grid(row=0, column=2, sticky="ns")
  579. label4.grid(row=0, column=3, sticky="nsew")
  580.  
  581. window.mainloop()
  582. --------------------------------------------------------------------------------------
  583. .grid()                        .pack()
  584. sticky="ns"     fill=tk.Y
  585. sticky="ew"     fill=tk.X
  586. sticky="nsew"   fill=tk.BOTH
  587. -----------------------------------------------------------------------------
  588. import tkinter as tk
  589.  
  590.  
  591. window = tk.Tk()
  592.  
  593. window.title("Simple Text Editor")
  594.  
  595.  
  596. window.rowconfigure(0, minsize=800, weight=1)
  597.  
  598. window.columnconfigure(1, minsize=800, weight=1)
  599.  
  600.  
  601. txt_edit = tk.Text(window)
  602.  
  603. frm_buttons = tk.Frame(window, relief=tk.RAISED, bd=2)
  604.  
  605. btn_open = tk.Button(frm_buttons, text="Open")
  606.  
  607. btn_save = tk.Button(frm_buttons, text="Save As...")
  608. ---------------------------------------------------------------------------------------
  609. window = tk.Tk()
  610.  
  611. window.title("Simple Text Editor")
  612.  
  613.  
  614. window.rowconfigure(0, minsize=800, weight=1)
  615.  
  616. window.columnconfigure(1, minsize=800, weight=1)
  617.  
  618.  
  619. txt_edit = tk.Text(window)
  620.  
  621. frm_buttons = tk.Frame(window, relief=tk.RAISED, bd=2)
  622.  
  623. btn_open = tk.Button(frm_buttons, text="Open", command=open_file)
  624.  
  625. btn_save = tk.Button(frm_buttons, text="Save As...", command=save_file)
  626.  
  627.  
  628. btn_open.grid(row=0, column=0, sticky="ew", padx=5, pady=5)
  629.  
  630. btn_save.grid(row=1, column=0, sticky="ew", padx=5)
  631.  
  632.  
  633. frm_buttons.grid(row=0, column=0, sticky="ns")
  634.  
  635. txt_edit.grid(row=0, column=1, sticky="nsew")
  636.  
  637.  
  638. window.mainloop()
  639. --------------------------------------------------------------------------------
  640. import tkinter as tk
  641.  
  642. def increase():
  643.     value = int(lbl_value["text"])
  644.     lbl_value["text"] = f"{value + 1}"
  645.  
  646. def decrease():
  647.     value = int(lbl_value["text"])
  648.     lbl_value["text"] = f"{value - 1}"
  649.  
  650. window = tk.Tk()
  651.  
  652. window.rowconfigure(0, minsize=50, weight=1)
  653. window.columnconfigure([0, 1, 2], minsize=50, weight=1)
  654.  
  655. btn_decrease = tk.Button(master=window, text="-", command=decrease)
  656. btn_decrease.grid(row=0, column=0, sticky="nsew")
  657.  
  658. lbl_value = tk.Label(master=window, text="0")
  659. lbl_value.grid(row=0, column=1)
  660.  
  661. btn_increase = tk.Button(master=window, text="+", command=increase)
  662. btn_increase.grid(row=0, column=2, sticky="nsew")
  663.  
  664. window.mainloop()
  665. -----------------------------------------------------------------------------
  666. import random
  667. import tkinter as tk
  668.  
  669. def roll():
  670.     lbl_result["text"] = str(random.randint(1, 6))
  671.  
  672. window = tk.Tk()
  673. window.columnconfigure(0, minsize=150)
  674. window.rowconfigure([0, 1], minsize=50)
  675.  
  676. btn_roll = tk.Button(text="Roll", command=roll)
  677. lbl_result = tk.Label()
  678.  
  679. btn_roll.grid(row=0, column=0, sticky="nsew")
  680. lbl_result.grid(row=1, column=0)
  681.  
  682. window.mainloop()
  683. -------------------------------------------------------------------------------
  684. import tkinter as tk
  685.  
  686. def fahrenheit_to_celsius():
  687.     """Convert the value for Fahrenheit to Celsius and insert the
  688.    result into lbl_result.
  689.    """
  690.     fahrenheit = ent_temperature.get()
  691.     celsius = (5 / 9) * (float(fahrenheit) - 32)
  692.     lbl_result["text"] = f"{round(celsius, 2)} \N{DEGREE CELSIUS}"
  693.  
  694. # Set up the window
  695. window = tk.Tk()
  696. window.title("Temperature Converter")
  697. window.resizable(width=False, height=False)
  698.  
  699. # Create the Fahrenheit entry frame with an Entry
  700. # widget and label in it
  701. frm_entry = tk.Frame(master=window)
  702. ent_temperature = tk.Entry(master=frm_entry, width=10)
  703. lbl_temp = tk.Label(master=frm_entry, text="\N{DEGREE FAHRENHEIT}")
  704.  
  705. # Layout the temperature Entry and Label in frm_entry
  706. # using the .grid() geometry manager
  707. ent_temperature.grid(row=0, column=0, sticky="e")
  708. lbl_temp.grid(row=0, column=1, sticky="w")
  709.  
  710. # Create the conversion Button and result display Label
  711. btn_convert = tk.Button(
  712.     master=window,
  713.     text="\N{RIGHTWARDS BLACK ARROW}",
  714.     command=fahrenheit_to_celsius
  715. )
  716. lbl_result = tk.Label(master=window, text="\N{DEGREE CELSIUS}")
  717.  
  718. # Set up the layout using the .grid() geometry manager
  719. frm_entry.grid(row=0, column=0, padx=10)
  720. btn_convert.grid(row=0, column=1, pady=10)
  721. lbl_result.grid(row=0, column=2, padx=10)
  722.  
  723. # Run the application
  724. window.mainloop()
  725. ===========================END==========================
  726.  
  727.  
  728.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement