Skip to main content

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

Project description

PyQt Country Picker

PyPI Python Build Coverage License

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

pyqtcountrypicker

Features

  • Supports 235 countries and territories
  • Supports only showing 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.0.tar.gz (964.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyqtcountrypicker-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 1b880c07ec54f91ad9901c513df60cb490161d05a98fa7b8af268812102c765d
MD5 373fba9bb683258d393706ea9e287dbc
BLAKE2b-256 102a76b8c422c7d428accb30bf7187aa9580eb3230b9350bc42537d0bff577f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqtcountrypicker-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72527375f2988126c901fb74abc1eca422c680a6a69189deaa4f60d097ed200d
MD5 bbd377f81b21f1c9e35e2468aed0a45d
BLAKE2b-256 239c96d86fe14f6e8346379f34fb4ba28777c5d1837462ac5e9cfe13ea973a19

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