範例-Tkinter with SQL
思路:
連接 SQL
( Sqlite / MySQL / ... )-> 設定 SQL 欄位與類別 -> 建立畫面。
安裝設置:
如果是連接 MySQL
則可以使用 mysql-connect 或 mysql-connector
cmd
py -m install mysql-connect-python
py -m install mysql-connector
引入Tkinter
py
import tkinter
from tkinter import ttk
from tkinter import messagebox
設定連接 SQL
py
import mysql.connector
link_mysql=mysql.connector()
def login_db(user,psd)
if psd:
db=link_mysql.connect(host='localhost', user=user, password=psd, db='db_table')
cursor=db.cursor()
else:
db=link_mysql.connect(host='localhost', user=user, db='db_table')
cursor=db.cursor()
savequery = "select * from DB"
try:
cursor.execute(savequery)
myresult=cursor.fetchall()
for x in myresult:
print (x)
print('Welcome')
except:
db.rollback()
print('Error')
設定畫面
py
參考
- Python And MySQL - How to Delete Data From MySQL Database In Python Tkinter
- Python MySQL CRUD Operation, Batch Processing, GUI Development Using Python
- Tkinter and MySQL Desktop App - Remote Monitoring
- Python-GUI-part 2-with Tkinter-and MySql Interfacing
- Python SQLite Data Entry Form with Tkinter tutorial for beginners - Python GUI project
- tkinter-data-entry
- Creating a Python Graphical User Interface Application with Tkinter
- Create a GUI Using Tkinter and Python
- Create MySQL Database Login Page in Python using Tkinter