2010-02-14 101 views
10
from Tkinter import * 
import socket, sys 
from PIL import Image, ImageTk 

root = Tk() 
root.title("Whois Tool") 
root.resizable(0, 0) 

text = Text() 
text1 = Text() 

image = Image.open("hacker2.png") 
photo = ImageTk.PhotoImage(image) 

label = Label(root, image=photo) 
label.pack() 


text1.config(width=15, height=1) 
text1.pack() 

def button1(): 
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
     s.connect(("com.whois-servers.net", 43)) 
     s.send(text1.get("1.0", END) + "\r\n") 
     response = '' 
     while True: 
      a = s.recv(4096) 
      response += a 
      if a == '': 
       break 
     s.close() 
     text.insert(END, response) 

def clear(): 
     text.delete("1.0", END) 


b = Button(root, text="Enter", width=10, height=2, command=button1) 
b.pack() 

c = Button(root, text="Clear", width=10, height=2, command=clear) 
c.pack() 

scrollbar = Scrollbar(root) 
scrollbar.pack(side=RIGHT, fill=Y) 
text.config(width=60, height=15) 
text.pack(side=LEFT, fill=Y) 
scrollbar.config(command=text.yview) 
text.config(yscrollcommand=scrollbar.set) 


root.mainloop() 

我如何調整根窗口,或者我如何可以調整圖像尺寸正好與根窗口按鈕或拉布勒和等..感謝如何調整Tkinter中的根窗口?

回答

26

對於500×500的窗口,你會用

root.geometry("500x500") 

至於圖片大小調整,我不相信Tkinter支持它。您將不得不使用諸如PIL之類的庫來將圖像調整爲窗口分辨率。 - example resize code -

+0

Tkinter開箱即可支持的唯一縮放比例是兩倍。 – 2010-02-14 13:47:48

+0

@布賴恩,我相信你,但是在一些基本的搜索之後,我無法找到任何信息。出於好奇,你將如何實現? – Sleepingrock 2010-02-14 13:51:01

+0

我的不好。 Tk允許您縮放或縮放圖像,但不會在Tkinter界面中顯示。 – 2010-02-14 18:11:18