これは、メインプログラム()である:tkinterウィンドウ内からテキストを削除しますか?
def mainProgram():
typedCountry = e.get()
Country = typedCountry.lower()
print 'Your country is: ' + typedCountry + '\n'
if Country in bannedCountries:
banned(typedCountry)
if Country in cpBannedCountries:
cpBanned(typedCountry)
if Country in skrillBannedCountries:
skrillBanned(typedCountry)
if Country in bacsCountries:
Bacs(typedCountry)
if Country in sepaCountries:
sepa(typedCountry)
if Country in eftCountries:
eft(typedCountry)
if Country in ltdCountries:
ltd(typedCountry)
if Country in marketsCountries:
markets(typedCountry)
私はボックスに国を入力するようユーザーに依頼し、私は別の国のいくつかのリストを持っている、と私は、ユーザーの入力がすべてのリストで国のいずれかと一致するかどうかを確認します。もしそうなら、私は行を印刷する別の関数を実行します。
これは私がいくつかの異なる国のリスト、およびだけで、ユーザーのためのものを印刷ダースかそこらの機能を持っている主なTkinterのコードこの前
master = Tk()
e = Entry(master)
e.pack()
e.focus_set()
def clear_text():
#WHAT TO ENTER HERE???
b = Button(master, text = "Search", bg="lightyellow", command = mainProgram)
b.pack()
c = Button(master, text="Quit", bg="orange",
command=master.quit)
c.pack()
d = Button(master, text="Clear", bg="orange",
command=clear_text)
d.pack()
mainloop()
あり、それはここでは関係ありません。
私はtkinterを使ってユーザーが国を入力できる入力ボックス(typedCountryに入力が割り当てられます)と検索、クリア、終了の3つのボタンを作成します。検索はmainProgram()関数を実行し、返された関数はtkinterボックスに出力されます。しかし、どこに印刷されているのか正確にはわからないので、テキストボックスの内容を完全に破棄せずに削除するように[クリア]ボタンに指示する方法はわかりません。
これは私が言う米国を検索するとき、それがどのように見えるかです:、
https://i.stack.imgur.com/omJPV.jpg
あなたが見ることができるように1が出力されます。その後、私はオーストリアの検索
https://i.stack.imgur.com/mPCBm.jpg
もう一方の下では、私はボックスからそれらをクリアする必要があります。私はtkinterがこれをどこに印刷しているのか分からないので、私が何をしてもそれをクリアすることはできません。それは
# -*- coding: utf-8 -*-
from tkinter import *
import tkMessageBox
import os
allCountries = ['afghanistan','aland','albania','algeria','american samoa','andorra',
'angola','anguilla','argentina','armenia','aruba','australia','austria','bahamas',
'bahrain','bangladesh','barbados','belarus','belgium','belize','benin','bermuda',
'bhutan','bolivia','bonaire','bosnia and herzegovina','botswana','brazil','brunei',
'bulgaria','burkina faso','burma','burundi','cambodia','cameroon','cape verde',
'cayman islands','central african republic','chad','colombia','comoros','congo',
'cook islands','costa rica','cote d\'ivoire','crimea','croatia','cuba','cyprus',
'czech republic','denmark','djibouti','dominican republic','ecuador','egypt',
'el salvador','equatorial guinea','eritrea','estonia','ethiopia','falkland islands (malvinas)',
'faroe islands','finland','france','gabon','gambia','germany','ghana','greece',
'greenland','grenada','guam','guatemala','guinea','guinea-bissau','guyana',
'haiti','hungary','iceland','india','iran','iraq','ireland','italy','jamaica',
'japan','jordan','kazakhstan','kenya','kiribati','kosovo','kuwait','kyrgyzstan',
'laos','latvia','lebanon','lesotho','liberia','libya','liechtenstein','lithuania',
'luxembourg','macao','macedonia','madagascar','malawi','malaysia','maldives',
'mali','malta','marshall islands','martinique','mauritania','mauritius','mayotte',
'mexico','micronesia','moldova','monaco','mongolia','montenegro','montserrat',
'morocco','mozambique','myanmar','namibia','nauru','nepal','netherlands','new zealand',
'nicaragua','niger','nigeria','north korea','northern mariana islands','norway',
'oman','pakistan','palau','panama','papua new guinea','paraguay','peru','philippines',
'poland','portugal','puerto rico','qatar','romania','russia','rwanda','saint helena',
'saint kitts and nevis','saint lucia','saint vincent and the grenadines','samoa',
'sao tome and principe','saudi arabia','senegal','serbia','seychelles','sierra leone',
'singapore','slovakia','slovenia','solomon islands','somalia','south africa','south korea',
'spain','sri lanka','sudan','suriname','swaziland','sweden','switzerland','syria',
'taiwan','tajikistan','tanzania','thailand','togo','tokelau','tonga','trinidad and tobago',
'tunisia','turkey','turkmenistan','turks and caicos islands','tuvalu','uganda','ukraine',
'united kingdom','united states','uruguay','uzbekistan','vanuatu','venezuela',
'virgin islands, u.s.','western sahara','yemen','zambia','zimbabwe','palestine'
]
bannedCountries = ['afghanistan','american samoa','belarus','brazil','burundi',
'central african republic','crimea','congo','cook islands','cote d\'ivoire','crimea','cuba',
'guam','iran','japan','liberia','libya','myanmar','new zealand','north korea',
'northern mariana islands','puerto rico','russia','singapore','somalia','south korea',
'sudan','south sudan','syria','tokelau','turkey','ukraine','united states','vanuatu','virgin islands',
'western sahara','zimbabwe', 'timor-leste']
cpBannedCountries = ['venezuela','united states','belarus','bosnia and herzegovina',
'burundi','cote d\'ivoire','cuba','iran','iraq','kosovo','lebanon','liberia',
'macedonia','montenegro','myanmar',
'nigeria','north korea','saint helena','somalia','sudan']
skrillBannedCountries = ['angola','barbados','benin','burkina faso','cape verde',
'comoros','djibouti','faroe islands','gambia','greenland','grenada','guyana','laos',
'liechtenstein','macao','martinique','mongolia','namibia','niger','palau','samoa',
'suriname','tajikistan','togo','trinidad and tobago','turkmenistan']
bacsCountries = ["united kingdom",'ireland']
eftCountries = ['australia']
sepaCountries = ['austria','belgium','bulgaria','croatia','cyprus','czech republic','check',
'denmark','estonia','finland','france','french guiana','germany','greece','gibraltar',
'hungary','iceland','guadeloupe'
'ireland','italy','latvia','liechtenstein','lithuania','luxembourg','malta',
'martinique','mayotte','monaco','netherlands','norway','poland','portugal',
'romania','slovakia','slovenia','spain','sweden','switzerland','united kingdom']
ltdCountries = ['austria','belgium','bulgaria','croatia','cyprus','czech republic',
'colombia','denmark','estonia','finland','france','germany','greece','hungary','ireland',
'italy','latvia','lithuania','luxembourg','malta','netherlands','poland','portugal',
'romania','slovakia','slovenia','spain','united kingdom']
marketsCountries = ['albania','algeria','andorra','angola','anguilla','armenia',
'aruba','bahamas','bangladesh','barbados','belize','benin','bermuda','bhutan',
'bonaire','bosnia','herzegovina','bosnia and herzegovina','botswana','brunei',
'burkina faso','burma','cambodia','cameroon','cape verde','cayman islands',
'chad','comoros','djibouti','equatorial guinea','eritrea','ethiopia','falkland islands (malvinas)',
'faroe islands','gabon','gambia','ghana','greenland','grenada','guinea','guinea-bissau',
'guyana','haiti','iceland','india','jamaica','jordan','kazakhstan','kenya',
'kiribati','kosovo','kyrgyzstan','laos','lesotho','liechtenstein','macao',
'macedonia','madagascar','malawi','malaysia','maldives','mali','marshall islands',
'mauritania','mauritius','micronesia','mongolia','morocco','mozambique','namibia',
'nauru','nepal','niger','nigeria','norway','pakistan','palau','papua new guinea',
'philippines','rwanda','saint helena','saint kitts and nevis','saint lucia','saint vincent and the grenadines',
'samoa','sao tome and principe','senegal','serbia','seychelles','sierra leone',
'solomon islands','sri lanka','suriname','swaziland','tajikistan','tanzania','togo',
'tonga','trinidad and tobago','tunisia','turkmenistan','turks and caicos islands','tuvalu',
'uganda','uzbekistan','yemen','zambia','palestine']
ibanCountries = [
'lebanon', 'albania','andorra','austria', 'azerbaijan','bahrain','belgium','bosnia and herzegovina',
'brazil','bulgaria','croatia','cyprus','czech republic','denmark', "estonia",'faroe islands',
'finland','france','french guiana','germany','gibraltar','greece','guadeloupe','guernsey','hungary',
'iceland','ireland','isle of man','israel','italy','jersey','jordan','kuwait','latvia','liechtenstein',
'lithuania','luxembourg','macedonia','malta','martinique','mauritania','mauritius','mayotte',
'moldova','monaco','montenegro','netherlands','norway','pakistan','poland','portugal',
'qatar','reunion','romania','san marino','saudi arabia','serbia','slovakia','slovenia','spain',
'sweden','switzerland','united kingdom','saint barthelemy','saint martin','saint pierre and miquelon',
'tunisia','united arab emirates','kosovo'
]
noLPOACountries = ['austria', 'belgium','bulgaria','croatia','cyprus', 'czech republic',
'denmark', "estonia",'finland','france','germany','greece','hungary','iceland','ireland',
'italy','latvia','liechtenstein','lithuania','luxembourg','malta','netherlands',
'norway','poland','portugal','romania','slovakia','slovenia','spain','sweden','switzerland']
max50cpCountries = ['france','germany','greece','italy']
zuluBannedCountries = ['italy']
idchecklistCountries =['kenya']
nonidchecklistCountries = ['jordan','kuwait','oman','qatar','saudi arabia',
'united arab emirates']
def banned(x):
if 'kingdom' not in x:
Label(master, text="""Clients from %s cannot apply for a live account with FXCM.""" % x).pack()
else:
return
def cpBanned(x):
Label(master, text="""Clients from %s cannot use credit/debit cards.""" % x).pack()
def cpAllowed(x):
Label(master, text="Clients from %s can deposit with credit cards." % x).pack()
def skrillBanned(x):
Label(master, text="Clients from %s cannot use Skrill" % x).pack()
def Bacs(x):
Label(master, text="""Clients from %s can use BACS if their bank account is located in
%s and both their bank account and their FXCM account is in GBP.\nClients from %s can
apply for a Spreadbetting account.""" % (x, x, x)).pack()
def sepa(x):
Label(master, text="""Clients from %s can use SEPA if their bank account is located either in
%s or in another European country, and both their bank account and their FXCM account is in EUR.
Clients from %s can have a maximum leverage of 200:1.""" % (x, x, x)).pack()
def eft(x):
Label(master, text="""Clients from %s can use EFT if their bank account is located in
%s, and both their bank account and their FXCM account is in AUD.\nClients in %s must open with FXCM AU""" % (x, x, x)).pack()
def ltd(x):
Label(master, text="Clients from %s must open with FXCM LTD" % x).pack()
def markets(x):
Label(master, text="Clients from %s must open with FXCM Markets" % x).pack()
def noLPOA(x):
Label(master, text="""All traders (MMs, IBs, family members, etc.) domiciled
within %s and/or managing funds for residents of %s must be regulated.
Managers acquiring clients across %s must have the appropriate passport or license
to do so.""" % (x, x, x)).pack()
def iban(x):
lbl['text'] = "IBAN is required for all wire withdrawals with a beneficiary bank account located in %s." % x
def max50cp(x):
Label(master, text="Residents of %s are NOT eligible for the ATG 50K CP deposit maximum. " % x).pack()
def zulu(x):
Label(master, text="Residents of %s cannot use ZuluTrader. " % x).pack()
def idchecklist(x):
Label(master, text="""For applicants residing in %s who have difficulty
submitting a valid proof of residence, we can accept the ID checklist
as an alternative. In addition, these clients will only be required
to submit one photo ID and P.O. box proof of residence with the ID
Checklist in lieu of two photo IDs.
""" % x).pack()
def nonidchecklist(x):
Label(master, text="""For applicants from %s who have difficulty submitting
a valid proof of residence and reside in Kuwait, they are not required to
send in an ID checklist or extra ID when submitting a POR listing a P.O.
Box as long as the city/state matches the application. If the city/ state
does not match, the ID checklist is required to satisfy the account opening
requirements
""" % x).pack()
def notFound(x):
Label(master, text="Country %s was not found, please try again" % x).pack()
def printAsterix():
Label(master, text="*"*40).pack()
def mainProgram():
typedCountry = e.get() # This is the text you may want to use later
if not typedCountry:
return
lowerCountry = typedCountry.lower()
upperCountry = typedCountry.title()
if lowerCountry in bannedCountries: #banned countries
banned(upperCountry)
if lowerCountry in cpBannedCountries:#cp banned countries
cpBanned(upperCountry)
if lowerCountry in skrillBannedCountries: #skrill banned countries
skrillBanned(upperCountry)
if lowerCountry not in cpBannedCountries and lowerCountry not in bannedCountries and lowerCountry in allCountries:
cpAllowed(upperCountry) #cp allowed countries
if lowerCountry in sepaCountries: #sepa allowed countries (EEA)
sepa(upperCountry)
if lowerCountry in eftCountries: #eft allowed countries (AU)
eft(upperCountry)
if lowerCountry in ltdCountries: #LTD required
ltd(upperCountry)
if lowerCountry in marketsCountries: #markets required
markets(upperCountry)
if lowerCountry in noLPOACountries: #lpoa not available
noLPOA(upperCountry)
if lowerCountry in ibanCountries: #iban required
iban(upperCountry)
if lowerCountry in max50cpCountries:
max50cp(upperCountry)
if lowerCountry in zuluBannedCountries:
zulu(upperCountry)
if lowerCountry in idchecklistCountries:
idchecklist(upperCountry)
if lowerCountry in nonidchecklistCountries:
nonidchecklist(upperCountry)
if lowerCountry not in allCountries: #not found
notFound(typedCountry)
printAsterix()
master = Tk()
e = Entry(master)
e.pack()
e.focus_set()
def clear_text():
lbl.withdraw()
b = Button(master, text = "Search", bg="lightyellow", command = mainProgram)
b.pack()
c = Button(master, text="Quit", bg="orange",
command=master.quit)
c.pack()
d = Button(master, text="Clear", bg="orange",
command=clear_text)
d.pack()
mainloop()
*「tkinterがどこに印刷しているのか分からないから」* tkinterがこれをどこに印刷しているのか分からないのはどういう意味ですか?このプログラムを書いたのですか?また、説明した問題のコードがあまりにも多く含まれています。 [このガイド](https://stackoverflow.com/help/mcve)の後にMCVEを作成してください。 –
すべてのラベルをフレームに配置し、フレームを破棄して再作成するか、フレームのすべての子を破棄することができます。 –
@EthanField私はすでにコードを編集して、無関係なものをすべて削除しました。そして、私がtkinterがこれを作っているのを知らないと言うと、私はウィジェットのどの部分が印刷されているのか正確には分かりません。それはマスターのtk()ボックスではなく、ボタンのどれでもなく、ラベルボックスではありません。アクセシブルなコード次元 –