ویرگول
ورودثبت نام
آرتین کریمیان
آرتین کریمیانروبیکا من : https://rubika.ir/artinkarimian3 سایت من : https://sites.google.com/view/artin-karimian
آرتین کریمیان
آرتین کریمیان
خواندن ۴ دقیقه·۶ ماه پیش

نصب کتابخانه آرتین کریمیان

خب برای امروز کتابخانه های (textwrap و os ) را لازم دارید

خب یکجا برای نگهداری فایل کتابخانه بسازید یعنی یک پوشه به نام artin بسازید و یک پایتون بسازید و کد زیر را داخلش ذخیره با نام aacc و آن را اجرا کنید :

import os import textwrap package_name = "artinkarimian" init_code = r''' """ artinkarimian A simple Python GUI + web utility library """ import re import urllib.request import webbrowser import tkinter as tk from tkinter import messagebox __version__ = "1.0.0" class Window: def __init__(self, title="artinkarimian Window", size="600x400", bg="white"): self.root = tk.Tk() self.root.title(title) self.root.geometry(size) self.root.configure(bg=bg) def set_title(self, title): self.root.title(title) def set_size(self, size): self.root.geometry(size) def set_bg(self, color): self.root.configure(bg=color) def run(self): self.root.mainloop() def timer(self, ms, func): self.root.after(ms, func) class Label: def __init__(self, window, text="", x=None, y=None, pack=True, **kwargs): self.widget = tk.Label(window.root, text=text, **kwargs) if x is not None and y is not None: self.widget.place(x=x, y=y) elif pack: self.widget.pack() def set_text(self, text): self.widget.config(text=text) class Button: def __init__(self, window, text="Button", command=None, x=None, y=None, pack=True, **kwargs): self.widget = tk.Button(window.root, text=text, command=command, **kwargs) if x is not None and y is not None: self.widget.place(x=x, y=y) elif pack: self.widget.pack() def set_text(self, text): self.widget.config(text=text) class Entry: def __init__(self, window, x=None, y=None, pack=True, **kwargs): self.widget = tk.Entry(window.root, **kwargs) if x is not None and y is not None: self.widget.place(x=x, y=y) elif pack: self.widget.pack() def get(self): return self.widget.get() def set(self, value): self.widget.delete(0, tk.END) self.widget.insert(0, value) class TextBox: def __init__(self, window, width=40, height=10, x=None, y=None, pack=True, **kwargs): self.widget = tk.Text(window.root, width=width, height=height, **kwargs) if x is not None and y is not None: self.widget.place(x=x, y=y) elif pack: self.widget.pack() def get(self): return self.widget.get("1.0", tk.END).strip() def set(self, value): self.widget.delete("1.0", tk.END) self.widget.insert("1.0", value) def show_info(title="Info", message="Hello"): messagebox.showinfo(title, message) def show_warning(title="Warning", message="Warning message"): messagebox.showwarning(title, message) def show_error(title="Error", message="Error message"): messagebox.showerror(title, message) def extract_links(text): """ Extract links from plain text or HTML. """ pattern = r'https?://[^\s"\'<>]+' return re.findall(pattern, text) def extract_domains(text): """ Extract domain names from found links. """ links = extract_links(text) domains = [] for link in links: match = re.findall(r'https?://([^/]+)', link) if match: domains.append(match[0]) return domains def open_link(url): """ Open a URL in the default browser. """ webbrowser.open(url) def fetch_html(url, timeout=10): """ Download HTML content from a URL. """ req = urllib.request.Request( url, headers={"User-Agent": "Mozilla/5.0"} ) with urllib.request.urlopen(req, timeout=timeout) as response: return response.read().decode("utf-8", errors="ignore") def save_text(filename, content): """ Save text to a file. """ with open(filename, "w", encoding="utf-8") as f: f.write(content) def read_text(filename): """ Read text from a file. """ with open(filename, "r", encoding="utf-8") as f: return f.read() def make_app(title="My App", size="600x400", bg="white"): """ Quick app creator. """ return Window(title=title, size=size, bg=bg) ''' setup_code = r''' from setuptools import setup, find_packages setup( name="artinkarimian", version="1.0.0", description="Simple GUI and web utility library", author="artinkarimian", packages=find_packages(), install_requires=[], ) ''' example_code = r''' import artinkarimian as ak app = ak.make_app(title="Demo App", size="700x500", bg="lightblue") label = ak.Label(app, text="سلام! این کتابخانه artinkarimian است", font=("Arial", 14), bg="lightblue") entry = ak.Entry(app, width=40) def show_text(): text = entry.get() label.set_text("شما نوشتید: " + text) btn = ak.Button(app, text="نمایش متن", command=show_text) textbox = ak.TextBox(app, width=60, height=10) def extract(): text = textbox.get() links = ak.extract_links(text) ak.show_info("Links", "\\n".join(links) if links else "لینکی پیدا نشد!") btn2 = ak.Button(app, text="استخراج لینک", command=extract) app.run() ''' readme_code = r''' # artinkarimian A simple Python GUI and web utility package. ## Features - Window creation - Button creation - Label creation - Entry input - TextBox input - Extract links from text/HTML - Extract domains - Open links in browser - Fetch HTML from websites - Save/read text files - Message boxes - Timer support ''' os.makedirs(package_name, exist_ok=True) with open(os.path.join(package_name, "__init__.py"), "w", encoding="utf-8") as f: f.write(textwrap.dedent(init_code).strip()) with open("setup.py", "w", encoding="utf-8") as f: f.write(textwrap.dedent(setup_code).strip()) with open("example.py", "w", encoding="utf-8") as f: f.write(textwrap.dedent(example_code).strip()) with open("README.md", "w", encoding="utf-8") as f: f.write(textwrap.dedent(readme_code).strip()) print("کتابخانه با موفقیت ساخته شد!") print() print("برای نصب، این دستورها را اجرا کن:") print("pip install .") print() print("بعد استفاده کن:") print("import artinkarimian")

بعد از اجرا در همون پوشه سی ام دی را باز کنید .

یعنی از دستور cd استفاده کنید

حالا دستور pip install . را بزنید .

حتما اون نقظه را بزنید

حالا پس از این از این به بعد در پایتون بروید بزنید import artinkarimian براتون میاره

قابلیت ها :

  • شبیه tk پنجره بسازد

  • دکمه بسازد

  • لینک را از متن/وب جدا کند

  • Label بسازد

  • Entry/input بسازد

  • TextBox بسازد

  • HTML صفحه را بگیرد

  • لینک را در مرورگر باز کند

  • فایل متنی ذخیره کند

  • فایل متنی بخواند

  • message box نشان دهد

  • timer داشته باشد

کانال روبیکا من : کانال روبیکا من : https://rubika.ir/artinkarimian3

اگر ایده یا پروژه ای دارید از طریق لینک زیر :
https://formafzar.com/form/zso58
پیام خود را وارد کنید راستی به تمام سوالات شما پاسخ داده میشود .

رمز داخل سایت (جهت نیاز) : artinkarimian125701

۵
۰
آرتین کریمیان
آرتین کریمیان
روبیکا من : https://rubika.ir/artinkarimian3 سایت من : https://sites.google.com/view/artin-karimian
کامپایل
کامپایل
نشر کامپایل با هدف آموزش ساده، کاربردی و عمیق مفاهیم برنامه‌نویسی و پایتون شکل گرفته است؛ انتشاراتی برای علاقه‌مندان به دنیای کدنویسی که می‌خواهند از سطح مبتدی تا حرفه‌ای، مسیر یادگیری را با کتاب‌هایی دقیق، روان و به‌روز طی کنند. در نشر کامپایل، تلاش می‌کنیم مفاهیم پیچیده‌ی دنیا
شاید از این پست‌ها خوشتان بیاید