Skip to main content

A simple, yet highly customizable country picker widget for PyQt and PySide

Project description

PyQt Country Picker

PyPI Python Build Coverage License

A simple, yet highly customizable country picker widget for PyQt and PySide

pyqtcountrypicker

Features

  • Supports 235 countries and territories
  • Supports only allowing certain countries
  • Fully customizable country names and flags
  • Works with PyQt5, PyQt6, PySide2, and PySide6

Installation

pip install pyqtcountrypicker

Usage

Import the CountryPicker class and instantiate it like a normal widget:

from PyQt6.QtWidgets import QMainWindow
from pyqtcountrypicker import CountryPicker


class Window(QMainWindow):

    def __init__(self):
        super().__init__(parent=None)
        
        # Create country picker
        self.country_picker = CountryPicker(self)

To get and set the currently selected country, you can use the getCurrentCountry() and setCurrentCountry() methods:

# Set current country
country_picker.setCurrentCountry('us')

# Get current country
selected_country = country_picker.getCurrentCountry()  # 'us'

To get notified when the selected country changes, you can subscribe to the countryChanged signal:

country_picker.countryChanged.connect(lambda country_code: print('country changed to ' + country_code))

Customization

  • Limiting the countries that can be selected:
eu_countries = [
    'at', 'be', 'bg', 'hr', 'cy', 'cz', 'dk', 'ee', 'fi',
    'fr', 'de', 'gr', 'hu', 'ie', 'it', 'lt', 'lu', 'lv',
    'mt', 'nl', 'pl', 'pt', 'ro', 'sk', 'si', 'es', 'se'
]

country_picker.setCountries(eu_countries)
  • Changing the country names:
# Setting a single country name
country_picker.setCountryName('af', 'Islamic Emirate of Afghanistan')

# Setting multiple country names at once
new_country_names = {
    'us': 'United States of America',
    'de': 'Federal Republic of Germany',
    'gb': 'England'
}
country_picker.setCountryNames(new_country_names)

# Resetting the country names
country_picker.resetCountryNames()
  • Changing the country flags:
# Setting a single flag
country_picker.setCountryFlag('af', QIcon('af_new_flag.png'))

# Setting multiple flags at once
new_country_flags = {
    'us': QIcon('us_alt.png'),
    'de': QIcon('de_alt.png'),
    'gb': QIcon('gb_alt.png')
}
country_picker.setCountryFlags(new_country_flags)

# Resetting the flags
country_picker.resetCountryFlags()
  • Enabling or disabling the country flags:
country_picker.setCountryFlagsEnabled(False)  # Default: True

Countries

Country name Country code Country flag
Afghanistan af
Albania al
Algeria dz
American Samoa as
Andorra ad
Angola ao
Anguilla ai
Antigua and Barbuda ag
Argentina ar
Armenia am
Aruba aw
Ascension Island sh-ac
Australia au
Austria at
Azerbaijan az
Bahamas bs
Bahrain bh
Bangladesh bd
Barbados bb
Belarus by
Belgium be
Belize bz
Benin bj
Bermuda bm
Bhutan bt
Bolivia bo
Bosnia and Herzegovina ba
Botswana bw
Brazil br
British Indian Ocean Territory io
British Virgin Islands vg
Brunei bn
Bulgaria bg
Burkina Faso bf
Burundi bi
Cambodia kh
Cameroon cm
Canada ca
Cape Verde cv
Caribbean Netherlands bq
Cayman Islands ky
Central African Republic cf
Chad td
Chile cl
China cn
Colombia co
Comoros km
Congo - Brazzaville cg
Congo - Kinshasa cd
Cook Islands ck
Costa Rica cr
Côte d'Ivoire ci
Croatia hr
Cuba cu
Curaçao cw
Cyprus cy
Czechia cz
Denmark dk
Djibouti dj
Dominica dm
Dominican Republic do
Ecuador ec
Egypt eg
El Salvador sv
Equatorial Guinea gq
Eritrea er
Estonia ee
Eswatini sz
Ethiopia et
Falkland Islands fk
Faroe Islands fo
Fiji fj
Finland fi
France fr
French Guiana gf
French Polynesia pf
Gabon ga
Gambia gm
Georgia ge
Germany de
Ghana gh
Gibraltar gi
Greece gr
Greenland gl
Grenada gd
Guadeloupe gp
Guam gu
Guatemala gt
Guinea gn
Guinea-Bissau gw
Guyana gy
Haiti ht
Honduras hn
Hong Kong hk
Hungary hu
Iceland is
India in
Indonesia id
Iran ir
Iraq iq
Ireland ie
Israel il
Italy it
Jamaica jm
Japan jp
Jordan jo
Kazakhstan kz
Kenya ke
Kiribati ki
Kosovo xk
Kuwait kw
Kyrgyzstan kg
Laos la
Latvia lv
Lebanon lb
Lesotho ls
Liberia lr
Libya ly
Liechtenstein li
Lithuania lt
Luxembourg lu
Macao mo
Madagascar mg
Malawi mw
Malaysia my
Maldives mv
Mali ml
Malta mt
Marshall Islands mh
Martinique mq
Mauritania mr
Mauritius mu
Mexico mx
Micronesia fm
Moldova md
Monaco mc
Mongolia mn
Montenegro me
Montserrat ms
Morocco ma
Mozambique mz
Myanmar mm
Namibia na
Nauru nr
Nepal np
Netherlands nl
New Caledonia nc
New Zealand nz
Nicaragua ni
Niger ne
Nigeria ng
Niue nu
Norfolk Island nf
North Korea kp
North Macedonia mk
Northern Mariana Islands mp
Norway no
Oman om
Pakistan pk
Palau pw
Palestine ps
Panama pa
Papua New Guinea pg
Paraguay py
Peru pe
Philippines ph
Poland pl
Portugal pt
Puerto Rico pr
Qatar qa
Réunion re
Romania ro
Russia ru
Rwanda rw
Samoa ws
San Marino sm
São Tomé & Príncipe st
Saudi Arabia sa
Senegal sn
Serbia rs
Seychelles sc
Sierra Leone sl
Singapore sg
Sint Maarten sx
Slovakia sk
Slovenia si
Solomon Islands sb
Somalia so
South Africa za
South Korea kr
South Sudan ss
Spain es
Sri Lanka lk
St. Barthélemy bl
St. Helena sh-hl
St. Kitts & Nevis kn
St. Lucia lc
St. Martin mf
St. Pierre & Miquelon pm
St. Vincent & Grenadines vc
Sudan sd
Suriname sr
Sweden se
Switzerland ch
Syria sy
Taiwan tw
Tajikistan tj
Tanzania tz
Thailand th
Timor-Leste tl
Togo tg
Tokelau tk
Tonga to
Trinidad & Tobago tt
Tunisia tn
Türkiye tr
Turkmenistan tm
Turks & Caicos Islands tc
Tuvalu tv
U.S. Virgin Islands vi
Uganda ug
Ukraine ua
United Arab Emirates ae
United Kingdom gb
United States us
Uruguay uy
Uzbekistan uz
Vanuatu vu
Vatican City va
Venezuela ve
Vietnam vn
Wallis & Futuna wf
Yemen ye
Zambia zm
Zimbabwe zw

The flag icons used are modified versions of the icons available in this repository.

License

This software is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqtcountrypicker-1.0.1.tar.gz (964.0 kB view details)

Uploaded Source

Built Distribution

pyqtcountrypicker-1.0.1-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file pyqtcountrypicker-1.0.1.tar.gz.

File metadata

  • Download URL: pyqtcountrypicker-1.0.1.tar.gz
  • Upload date:
  • Size: 964.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.3

File hashes

Hashes for pyqtcountrypicker-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9378a696b8f4de81d39ba66dcfc598fa9887e8b8dee0fe6e1aea188b68d695fb
MD5 7463b8f6760ee71fd78d53ba6e3879b1
BLAKE2b-256 d06cb33e23f2dbf976945560c141cc828b2a8c7ebc665703a607ca4ad93cbe74

See more details on using hashes here.

File details

Details for the file pyqtcountrypicker-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyqtcountrypicker-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 737f670ebb4dc8fe4f9a758f3cdae8afb37b24b1e05934be4bbe0b8620590a28
MD5 bb05f774b323b3b45abec3a7a4be3548
BLAKE2b-256 317a4d13f06b5abc4866ed383944f02fbcb1e9b5eb07f131e43564c892808445

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page