Python Code Notes

Information by python engineer

How to change a tkinter's widget color on or off hover

You can change widget color when on or off hover by binding "Motion" and "Leave"event to color change functions. This is an example using button widget. how to change tkinter's widget color on hover off hover on hover

How to create a simple dialog by yourself

If you want users to input something, you can use the tkinter.simpledialog module. But if you want to create a more complex or well-designed dialog, you can easily create one yourself. example example of a simple input dialog

How to "Just fit" tkinter main window to your display

Summarized how to just fit tkinter main window to the display edge. Normally the tkinter window is positioned slightly to the right of the position set using geometry method. You should take care if you want to just fit the window to your …

【django】ログインした状態のテストを行う方法【Python】

ログインした状態の動作をテストする方法を整理した。 TestCaseクラスのclient.force_loginメソッドを使用することで、ログインした状態でのテストを行うことができる。 from django.contrib.auth import get_user_model from django.test import TestCase f…

【django】herokuからMySQLを使用する方法【Python】

heroku上でMySQLを使用するための各設定方法を整理した。heroku上へのデプロイ、MySQL サーバーとWorkbnchのインストールが完了していることが前提。ローカル環境でMySQLを使用する方法は、以下の記事を参照。 www.python-beginners.com 目次 ClearDB MySQL…

【django】dotenvで環境ファイルを利用する方法【Python】

python-dotenvモジュールを使用することで、プログラム内で使用するパスワード等の値を環境変数ファイルで管理し、スクリプトファイル側から読み込むことができる。 以下、Djangoで設定したmysqlのユーザー名とパスワードを環境ファイルから読み出す例を示す…

【django】データベースをmysqlに変更する方法【Python】

データベースとしてデフォルトで指定されているsqlite3を、mysqlに変更する方法を整理する。 目次 mysqlのインストール データベース作成 settings.pyの修正 mysqlclientモジュールのインストール マイグレーション・テーブルの確認 【スポンサーリンク】 (a…

【django】プロジェクトを開始してアプリを登録する方法【Python】

Djangoを用いてプロジェクトを開始してアプリを登録するまでの流れを整理する。 まとめ ①プロジェクト生成(プロジェクト名:django_test) django-admin startproject django_test . ②アプリ追加(アプリ名:items) python manage.py startapp items ③アプリ登録…

【django】ListViewの使い方【Python】

データベース内のオブジェクトをリスト化して表示するための汎用クラスである、ListViewクラスの使用方法を整理する。 目次 基本的な使用例 ユーザー名を指定してリスト表示 【スポンサーリンク】 (adsbygoogle = window.adsbygoogle || []).push({}); 基本…

【tkinter】タイミングを指定して関数を実行する方法【Python】

画面を定期的にアップデートするなど、指定した時間経過後に自動的に関数を実行したい場面で便利な、afterメソッドについて使い方を整理した。 目次 一定時間経過後に関数を実行 定期的に関数を実行 time.sleep関数を使用した場合(動作しない) 【スポンサ…