473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to print the Entry() of a function in another functiion?

Hi, I'm trying to print the string of: Entry "motTexte" who is located in getWord(), in draw(). But everytime in write something in the entry, it prints an empty line in the Python IDLE.

The code:

Expand|Select|Wrap|Line Numbers
  1. from time import *
  2. from math import *
  3. from re import *
  4. from tkinter import *
  5.  
  6.  
  7.  
  8. def getWord():
  9.     rootMot = Toplevel(root)
  10.     motTexte = Entry(rootMot)
  11.     motTexte.get()
  12.     motTexte.pack()
  13.     getWord.motFinal = motTexte.get()
  14.     boutonMot = Button(rootMot, text="Submit", width=10,
  15.                        command=lambda: draw(rootMot))
  16.     boutonMot.pack()
  17.  
  18.  
  19. def draw(widget):
  20.     print(getWord.motFinal)
  21.     widget.destroy()
  22.     gameDraw = Canvas(root, width=200, height=100)
  23.     gameDraw.pack()
  24.  
  25.  
  26.  
  27. #Create the menu
  28. root = Tk()
  29. menu = Menu(root)
  30. root.config(menu=menu)
  31.  
  32.  
  33. gameOptions = Menu(menu)
  34. menu.add_cascade(label="Game", menu=gameOptions)
  35. gameOptions.add_command(label="New Game", command=getWord)
  36. gameOptions.add_command(label="Options...", command=getWord)
  37. gameOptions.add_separator()
  38. gameOptions.add_command(label="Exit", command=getWord)
  39.  
  40.  
  41. helpOptions = Menu(menu)
  42. menu.add_cascade(label="Help", menu=helpOptions)
  43. helpOptions.add_command(label="How to play...", command=getWord)
  44. helpOptions.add_command(label="About...", command=getWord)
  45. mainloop()
Thank you

PS: I'm french so sorry if you don't understand some variables :)
Nov 8 '14 #1
1 1298
bvdet
2,851 Expert Mod 2GB
At the time of assignment to getWord.motFinal, there is no text in motTexte. You can add motTexte as an argument in the button callback and call get() in draw().
Expand|Select|Wrap|Line Numbers
  1. def getWord():
  2.     rootMot = Toplevel(root)
  3.     motTexte = Entry(rootMot)
  4.     motTexte.get()
  5.     motTexte.pack()
  6.     boutonMot = Button(rootMot, text="Submit", width=10,
  7.                        command=lambda: draw(rootMot, motTexte))
  8.     boutonMot.pack()
  9.  
  10. def draw(top, widget):
  11.     print(widget.get())
  12.     top.destroy()
  13.     gameDraw = Canvas(root, width=200, height=100)
  14.     gameDraw.pack()
You should consider encompassing your dialogs in a class object where individual elements are created as instance objects and can be accessed by attribute reference (as in self.motTexte).
Nov 9 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: weiwei | last post by:
HI I am having a problem with print friendly function with asp, I have download some code regard with print friendly, it works fine with static html information, however, I have the dynamic pages...
0
by: MARK | last post by:
Hi, Can anyone help me with some vb code as i have little or no know of this programming language. I have a SQL server containing my datatbase and using an Access front end. I have two table:...
0
by: Jamie Pittman via AccessMonster.com | last post by:
I am currently using a form to track employee time to customer and warehouse. I want to be able to take information from one record and post this to tne next record(finish time on the first record...
3
by: Shannan Casteel via AccessMonster.com | last post by:
I have a table called tblParttest. It has fields PartNo, PartNo2, PartNo3, .. .., PartNo25 and Quantity, Quantity2, Quantity3, ...Quantity25. If I enter "1234" into the PartNo field and "4" into...
3
by: Steven Woody | last post by:
Hi, i am using gcc. in the following code void ( * on_data_receive_of_ph ) ( const short line, const uint8_t c ); .... printf( "addr of function = %x\n", (void*)on_data_receive_of_ph ) ---...
3
by: 50gumbys | last post by:
I have a field that uses a drop-list. When I select one of the options from the list, I'd like to make another field (it's a Yes/No field) on the form disabled, to ensure the user doesn't try to use...
1
by: Simon Gare | last post by:
Hi, have form on asp page with an email address field, when the user enters their email address I want it to populate another field automatically on the same page, some kind of OnBlur event....
1
by: somenath | last post by:
Hi ALL , I need to print the name of the function as my debug message. I have tried the following way #include<stdio.h> #include<stdlib.h> #define __STR(x) _VAL(x) #define _VAL(x) #x int...
2
by: tolokoban | last post by:
I read in the following thread that the "cmp" method is not needed for sorting and that "key" is egnough : http://bytes.com/topic/python/answers/844614-python-3-sorting-comparison-function but if...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.