小编Hon*_*Abe的帖子

如何使用Python 3.x获取网站的IP地址?

我有一个代表域名的字符串.如何使用Python 3.x获取相应的IP地址?像这样的东西:

>>> get_ip('http://www.stackoverflow.com')
'64.34.119.12'
Run Code Online (Sandbox Code Playgroud)

python ip dns

10
推荐指数
3
解决办法
9409
查看次数

如何在tkinter Canvas上创建Button?

我创建了一个Frame,然后创建了一个Canvas.
我接下来要做的是在画布上添加一个Button.
但是,当我打包按钮时,我看不到画布!

这是我尝试过的:

from Tkinter import Tk, Canvas, Frame, Button
from Tkinter import BOTH, W, NW, SUNKEN, TOP, X, FLAT, LEFT

class Example(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()

    def initUI(self):
        self.parent.title("Layout Test")
        self.config(bg = '#F0F0F0')
        self.pack(fill = BOTH, expand = 1)
                #create canvas
        canvas1 = Canvas(self, relief = FLAT, background = "#D2D2D2",
                                            width = 180, height = 500)
        canvas1.pack(side = TOP, anchor = NW, padx = 10, pady = 10)
        #add quit button
        button1 = …
Run Code Online (Sandbox Code Playgroud)

python user-interface tkinter button

7
推荐指数
1
解决办法
4万
查看次数

自定义密码重置邮件在Laravel中查看

如何更改laravel中密码重置电子邮件中显示的内容?就像用他的名字向用户说话并显示密码重置链接等.该电子邮件视图位于何处?

email laravel

7
推荐指数
2
解决办法
6509
查看次数

将科学记数法转换为十进制 - 蟒蛇

如何将科学记数法转换为浮点数?这是我想要避免的一个例子:

Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[78.40816326530613, 245068094.16326532]
>>> print a[0]/a[1]
3.19944395589e-07
>>> print float(a[0]/a[1])
3.19944395589e-07
>>> print float(a[0])/float(a[1])
3.19944395589e-07
Run Code Online (Sandbox Code Playgroud)

python scientific-notation floating-point-conversion

6
推荐指数
2
解决办法
2万
查看次数

内存在大型数据结构操作/处理中的使用

我有一些大的(~100 Mb)文件,我经常处理.虽然我在处理期间尝试删除不需要的数据结构,但内存消耗有点过高.我想知道是否有办法有效地操纵大数据,例如:

def read(self, filename):
    fc = read_100_mb_file(filename)
    self.process(fc)
def process(self, content):
    # do some processing of file content
Run Code Online (Sandbox Code Playgroud)

是否存在重复的数据结构?使用像self.fc这样的类范围属性不是更高效的内存吗?

我什么时候应该使用垃圾收集?我知道gc模块,但是我之后会调用它del fc吗?

更新
ps 100 Mb本身不是问题.但浮动转换,进一步处理显着增加工作集和虚拟大小(我在Windows上).

python garbage-collection memory-leaks data-structures

4
推荐指数
1
解决办法
3396
查看次数

使按钮一次只打开一个窗口(通过关闭Toplevel窗口启用按钮)

我想NewWinButton一次只创建一个新窗口,这意味着如果

if NewWin.winfo_exists() == 1:
   NewWinButton.config(state='disabled')
else:
   NewWinButton.config(state='normal')
Run Code Online (Sandbox Code Playgroud)

如果我在新窗口中添加一个按钮(QuitButton在本例中),我可以使这个工作:

import tkinter as tk

root = tk.Tk()
root.title('Main Window')
root.geometry('400x400')

def get_new_win():

    NewWin = tk.Toplevel(root)
    NewWin.title('New Window')
    NewWin.geometry('300x300')
    NewWinButton.config(state='disable')

    def quit_win():
        NewWin.destroy()
        NewWinButton.config(state='normal')

    QuitButton = tk.Button(NewWin,text='Quit', command=quit_win).pack()

NewWinButton = tk.Button(root,text='New Window', get_new_win).pack()

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

当且仅当我QuitButton用来关闭新窗口时,这是有效的; 但是,如果我在新窗口中使用关闭按钮,则NewWinButton将保持"禁用"状态.

谁能告诉我如何解决这个问题?

python tkinter

4
推荐指数
1
解决办法
7435
查看次数

为什么浮点上的简单数学运算会在VB.Net和Python中返回意外(不准确)?

x = 4.2 - 0.1  
Run Code Online (Sandbox Code Playgroud)

vb.net给出了4.1000000000000005
python给出的4.1000000000000005

Excel给出了4.1
calc calc给出4.1

这种情况发生的原因是什么?

python vb.net floating-point

3
推荐指数
2
解决办法
2545
查看次数

主框架的Python背景颜色

我希望我的主框架背景颜色为黑色.这是我尝试过的:

#!/usr/bin/python
import tkinter
from tkinter import *

root = Tk()
root.geometry("363x200")
root.resizable(0,0)
root.title("Emsg Server")
root.option_add("*background", "black")

v = StringVar()

Field = Message(root, textvariable=v, width=330, fg="blue")
Field.grid()

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

我上面的尝试root.option_add("*background", "black"),只是创建了一个位于西北方的小黑盒子.

你如何使整个应用程序变黑?

python tkinter

3
推荐指数
1
解决办法
2万
查看次数

n Python中列表的最高值

获得给定列表的n个最高值的最佳方法是什么?如果我们处于与长度相比n相当小的情况下alist,是否有更高效的东西:

alist.sort()
return alist[0:n]
Run Code Online (Sandbox Code Playgroud)

python sorting

2
推荐指数
1
解决办法
1514
查看次数

列中按钮之间的垂直内边距

当我填充小部件时,它们都只是在同一帧上以 1 个大块的形式一起移动。我需要能够将它们分开并在同一框架上的每个小部件之间添加填充。这是我尝试过的代码的一部分:

def CreateDisplay(self):

    self.mainwindow = tk.Tk()
    self.mainwindow.geometry("800x600")
    self.mainwindow.wm_title(self.constants.NAME)
    self.mainwindow.resizable(width=False, height=False)

    self.frame_main = tk.Frame(master = self.mainwindow)
    self.frame_title = tk.Frame(master = self.frame_main)
    self.frame_test = tk.Frame(master = self.frame_main)
    self.frame_recentscore = tk.Frame(master = self.frame_main)
    self.frame_help = tk.Frame(master = self.frame_main)
    self.frame_exit = tk.Frame(master = self.frame_main)

    self.frame_main.pack(pady=15)
    self.frame_title.pack(anchor="c")
    self.frame_test.pack(pady=15)
    self.frame_recentscore.pack(pady=15)
    self.frame_help.pack(pady=15)
    self.frame_exit.pack(pady=15)

    self.label_title = tk.Label(self.frame_title, font=("purisa", 20), text="Business Studies Finance Revison:")

    self.label_title.pack()

    self.button_test = tk.Button(self.mainwindow, padx=54, pady=3, font=("Purisa",15), text="Take a Test", command=self.parent.test).pack()
    self.button_recentscore = tk.Button(self.mainwindow, font=("Purisa",15), text="View My Recent Scores", command=self.parent.recentscores).pack()
    self.button_help = tk.Button(self.mainwindow, …
Run Code Online (Sandbox Code Playgroud)

python tkinter

2
推荐指数
1
解决办法
1万
查看次数

Python:Unicode到html实体

我在将unicode转换为html实体时遇到问题.

这是我目前的代码:

>> name = u'\xc3\xa1\xc3\xa1\xc3\xa1\xc3\xa1'

>> entities = name.encode('ascii', 'xmlcharrefreplace')

>> print str(entities)
áááá
Run Code Online (Sandbox Code Playgroud)

每个\xc3\xa1= á(多字节字符),但当我将其转换为实体时,我为单个字符获得2个实体.

python unicode encoding character-encoding

1
推荐指数
1
解决办法
1891
查看次数