Tkinter Python Program Examples 3,5/5 8796 reviews
- Python Tkinter Script Example
- Python Tkinter Gui Examples
Active14 days ago
Python Tkinter.Entry Examples The following are code examples for showing how to use Tkinter.Entry. They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account. This call (say, for example, creating a button widget), is implemented in the Tkinter module, which is written in Python. This Python function will parse the commands and the arguments and convert them into a form that makes them look as if they had come from a Tk script instead of a Python script. Python GUI Programming (Tkinter) – Part I In this Python GUI programming tutorial you will learn about how to make GUI programs using Python Tkinter toolkit. Graphical User Interface, also known as GUI is one of the best features in programming that makes a program look visually more attractive than the normal text based programs covered with.
I am writing a program which should:
- Open a window with the press of a button.
- Close the newly opened window with the press of another button.
I'm using classes so I can insert the code into a larger program later. However, I can't get my buttons to load correctly.
Stevoisiak
7,2291212 gold badges5353 silver badges113113 bronze badges
ADB
ADB49533 gold badges77 silver badges2121 bronze badges
5 Answers
I rewrote your code in a more organized, better-practiced way:
Result:
Stevoisiak
7,2291212 gold badges5353 silver badges113113 bronze badges
Rushy Panchal
Rushy Panchal9,5521111 gold badges4545 silver badges7777 bronze badges
You need to specify the master for the second button. Otherwise it will get packed onto the first window. This is needed not only for Button
, but also for other widgets and non-gui objects such as StringVar
.
Quick fix: add the frame new
as the first argument to your Button
in Demo2
.
Possibly better: Currently you have Demo2
inheriting from tk.Frame
but I think this makes more sense if you change Demo2
to be something like this,
Just as a suggestion, you should only import tkinter
once. Pick one of your first two import statements. Drivers inland ma3303 sound.
Jared
Jared16.4k77 gold badges4141 silver badges5858 bronze badges
Halvor Holsten Strand
16.3k1515 gold badges5858 silver badges7474 bronze badges
SumantaSumanta
What you could do is copy the code from tkinter.py
into a file called mytkinter.py
, then do this code:
And you have two windows which don't collide!
WhyAreYouReadingThisWhyAreYouReadingThis
I tried to use more than two windows using the Rushy Panchal example above. The intent was to have the change to call more windows with different widgets in them. The butnew function creates different buttons to open different windows. You pass as argument the name of the class containing the window (the second argument is nt necessary, I put it there just to test a possible use. It could be interesting to inherit from another window the widgets in common.
Giovanni Python
Giovanni Python8,38511 gold badge1919 silver badges2828 bronze badges
Python Tkinter Script Example
Not the answer you're looking for? Browse other questions tagged pythonclasstkinterdestroy or ask your own question.
GUI Tk /
Alarm1 | Animation3 |
Back Fore ground1 | Beeper1 |
Border7 | Button32 |
Canvas8 | CheckBox7 |
Common Dialog9 | Cursor1 |
Dialog14 | Editor1 |
Event9 | Exception Dialog1 |
Focus1 | Frame23 |
Label16 | Layout40 |
LED1 | ListBox7 |
Menu Checkbox1 | Menu RadioButton1 |
Menu18 | MenuButton1 |
Message Box1 | OptionMenu1 |
Pack4 | Popup Menu1 |
RadioButton9 | Scale8 |
ScrollBar2 | StatusBar MessageField2 |
Table Grid5 | Text11 |
TextArea4 | TextField Entry12 |
Timer2 | Tk option database1 |
TK Root Window3 | ToolBar2 |
Top Level1 | UI Class15 |
UI Event1 |
Event /
Key Action15 | Mouse Action23 |
Mouse Draw3 |
GUI Pmw /
Pmw AboutDialog2 | Pmw Blt Tabset1 |
Pmw Border1 | Pmw ButtonBox5 |
Pmw Color2 | Pmw ComboBox7 |
Pmw ComboBoxDialog2 | Pmw Counter9 |
Pmw CounterDialog2 | Pmw Dialog8 |
Pmw EntryField15 | Pmw Error Handler2 |
Pmw Gauge1 | Pmw Grid2 |
Pmw Group8 | Pmw HistoryText1 |
Pmw Key Action1 | Pmw LabeledWidget2 |
Pmw LogicalFont1 | Pmw MegaWidget4 |
Pmw MenuBar2 | Pmw MessageBar2 |
Pmw MessageDialog7 | Pmw Multi line label2 |
Pmw OptionMenu4 | Pmw Password1 |
Pmw Performance1 | Pmw PromptDialog1 |
Pmw RadioSelect5 | Pmw ScrolledCanvas4 |
Pmw ScrolledField1 | Pmw ScrolledFrame1 |
Pmw ScrolledListBox5 | Pmw ScrolledText4 |
Pmw SelectionDialog2 | Pmw Splitpane3 |
Pmw StatusBar1 | Pmw Tab NoteBook4 |
Pmw TextDialog2 | Pmw TimeCounter2 |
Pmw Tooltips2 | Pmw Toplevel Megawidget1 |
Pmw Validation Field9 | Subclassing Pmw3 |
2D /
Arc2 | Bitmap2 |
Circle1 | Color2 |
Curve1 | Font7 |
Gif1 | Image1 |
Line5 | Oval3 |
Polygon1 | Rectangle2 |
Shape Border2 |
List /
List Append4 | List Assign5 |
List Cancatenation5 | List Compare3 |
List Comprehensive6 | List Count1 |
List Declaration1 | List Element Insert1 |
List Element Remove1 | List Element Replace1 |
List Element4 | List Empty1 |
List Extend3 | List Filter1 |
List In3 | List Index2 |
List Indexing7 | List Insert2 |
List Intersect2 | List Length2 |
List Loop6 | List Pop3 |
List Remove5 | List Repitition1 |
List Reverse2 | List Sliced7 |
List Sort3 | List Two Dimension2 |
Nested List3 | Return List1 |
Variables in List1 |
Tuple /
Nested Tuple1 | Tuple Concatination2 |
Tuple Condition1 | Tuple Creation6 |
Tuple Declaration4 | Tuple Display1 |
Tuple Element1 | Tuple Immutable1 |
Tuple In3 | Tuple Index4 |
Tuple Length2 | Tuple Loop3 |
Tuple Range1 | Tuple Repitition1 |
Tuple Returned1 | Tuple Slice2 |
Tuple toList2 | Tuple Zip1 |
Dictionary /
Dictionary Assignment4 | Dictionary Clear1 |
Dictionary Copy3 | Dictionary Declaration3 |
Dictionary Del1 | Dictionary Fetch1 |
Dictionary get3 | Dictionary has Key4 |
Dictionary items2 | Dictionary iteritems1 |
Dictionary Key6 | Dictionary List1 |
Dictionary Loop3 | Dictionary Output1 |
Dictionary popitem1 | Dictionary Print1 |
Dictionary setdefault1 | Dictionary Tuple3 |
Dictionary update2 | Dictionary values2 |
String /
Append1 | Format1 |
Loop2 | String Case2 |
String Cast5 | String center1 |
String Compare1 | String Concatenation3 |
String count1 | String cross Line1 |
String Declaration3 | String Ends1 |
String endsWith1 | String Escape4 |
String find2 | String In3 |
String Index4 | String join6 |
String Length6 | String ljust1 |
String Output2 | String Quotation3 |
String R1 | String Repitition2 |
String Replace5 | String rfind1 |
String rindex1 | String rjust1 |
String Slice6 | String Special Char1 |
String Split4 | String startsWith1 |
String strip1 | String toTitle1 |
String Variables2 | zfill1 |
Class /
Class abstract1 | Class add1 |
Class call1 | Class Constructor5 |
Class Define2 | Class Definition8 |
Class del1 | Class Dict2 |
Class fields10 | Class getattr2 |
Class getitem2 | Class getslice1 |
Class Inheritance12 | Class Instance1 |
Class instantiation1 | Class iter1 |
Class len1 | Class list1 |
Class metaclass1 | Class Method5 |
Class mul1 | Class Operator Add1 |
Class Private1 | Class radd1 |
Class repr1 | Class self1 |
Class setattr1 | Class str3 |
Class sub1 | Class Virtual6 |
Static1 |
Function /
Apply2 | Function as Parameters3 |
Function as Return2 | Function Default Argument10 |
Function Define7 | Function Dictionary Parameters4 |
Function Inner4 | Function Keyword Arguments3 |
Function Parameters5 | Function Recursive3 |
Function Return5 | Function Tuple Parameters6 |
Function type vars1 | Functional Programming5 |
lambda function5 | Return3 |
Buildin Function /
chr1 | Del1 |
dict1 | Dir3 |
enumerate1 | Eval1 |
filter4 | Float Function1 |
Generator Function3 | Generator3 |
id1 | in3 |
int cast2 | Iterable Object1 |
Iterator Behavior1 | Iterators1 |
len3 | list4 |
map6 | next2 |
ord2 | range8 |
reduce4 | repr6 |
reversed1 | sorted1 |
str4 | zfill1 |
zip7 |
Data Type /
Array1 | Bigger Number1 |
Bit3 | Boolean3 |
Complex Numbers6 | Decimal1 |
Float2 | Hex Function1 |
Hex Type1 | Int11 |
Long1 | maxint2 |
Oct Function1 | octal Type1 |
True2 | Type Conversion2 |
Data Structure /
bisect1 | Deque1 |
Queue1 | Set Declaration2 |
Set In1 | Set3 |
Stack2 |
Database /
DBM3 | MySQL3 |
ODBC1 | Pickle5 |
shelve3 |
File /
Dircetories4 | File Binary1 |
File Close3 | File IO Exception1 |
File Object1 | File Open1 |
File Pointer1 | File Read9 |
File Readline3 | File seek2 |
File Tell1 | File Text2 |
File Utilities1 | File Utility2 |
File Write6 | File Zip4 |
IO Error3 | Text File Read Write2 |
Text File Read8 | Text File Write4 |
Development /
Command Line3 | Compress1 |
Console Read4 | Date Time6 |
Doc String6 | Encode File2 |
Environment2 | Help2 |
isinstance1 | Logging1 |
Output Format25 | Path1 |
Random10 | Reflection1 |
Standard Read5 | Standard Redirect5 |
Standard Vars1 | stdout stderr6 |
Test1 | Timer1 |
User Input2 |
Language Basics /
And Or7 | Break4 |
Buildin Error2 | Catch Exceptions3 |
Comments3 | Continue3 |
def1 | Divide4 |
For In2 | For5 |
Garbage Collector1 | Global5 |
If10 | Import3 |
Local Variables2 | Locale1 |
Logical Operator1 | Module15 |
Multiply3 | Not1 |
Operator1 | Pass1 |
Plus1 | pprint1 |
Print3 | Raise1 |
Statement1 | Static Method2 |
Subtract1 | Text Encode3 |
Try Else2 | Try finally1 |
Try2 | Type2 |
Unicode9 | Variable Assign3 |
Variable Declaration2 | Variable Immutable2 |
Variable Reference1 | While12 |
Exception /
Python Tkinter Gui Examples
Exception Class3 | Exception finally1 |
Exception Handle6 | Exception Info3 |
Exception Raise2 | Exception Trace1 |
Exception Type1 | Value Error1 |
Math /
cos1 | E1 |
Log1 | Math Pow1 |
Max2 | Min2 |
Mod1 | Pi1 |
Power2 | Round2 |
Sin2 | sqrt1 |
Network /
Address Info3 | CGI5 |
Email8 | FTP4 |
Gopher Client5 | Host Info3 |
HTML Parser2 | HTTP POST1 |
Internet Access1 | IP Address1 |
Proxy1 | Remote File1 |
Server UDP2 | Socket Broadcast1 |
Socket Client3 | Socket Error Handle3 |
Socket Info1 | Socket Option1 |
Socket Pocket2 | Socket Server6 |
TCP5 | UDP4 |
URL7 | Web Client6 |
Web Page3 | Web Server1 |
Thread /
Thread Exit1 | Thread Sleep1 |
Thread Start1 | Thread Synchronize3 |
System /
System Cmd Mount3 | System Command1 |
System Error1 | System Exit1 |
System fork1 | System Info1 |
System Path4 | System pid1 |
System Time1 | System User1 |
System Variables3 |
XML /
Handler2 | SAX4 |
XML Children Node5 | XML Element4 |
XML Parse7 | XML Transform3 |
Utility /
API Helper2 | Command Line1 |
Command2 | Exception1 |
File Utility16 | Network Utility7 |
Programming21 | Regular Expressions1 |
Application /